1

the problem is that when i want to get the response from the server then it gives null

//url of web service        
url="http://www.google.com/ig/calculator?hl=en&q=12INR=?GBP"
var xmlHttp=new xmlHttpRequest();
//object of xml request
xmlHttp.open('GET', url, true);
//get method
xmlHttp.onreadystatechange = function(){
try{
        if (xmlHttp.readyState != 4) 
            return;                                 
        alert(xmlHttp.responseXML);
        var result = xmlHttp.responseXML.documentElement;
        var jsonString = result.childNodes[0].nodeValue;        
        var result1 = jsonParse(jsonString); 
        alert(result1.rhs);
        document.getElementById('results').innerHTML = innerHTML;
            }
    catch(e1){alert("erroe="+e1);}
};
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send(null); 

}

1 Answer 1

4

You can't do an AJAX call to www.google.com unless your page is already being served from the www.google.com domain.

https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript

Sign up to request clarification or add additional context in comments.

7 Comments

then what thing i have to do in this case???please explain in detail or can u post any relevant example for that so i can get responce from server...
Blame the guys who created thh annoyng same origin policy, of course. :) Anyway, the best course of action would be to either search for an alternative calculator API (for example, google maps has a JSONP javascript API that doesn't use AJAx and goes arouf the SOP) or you could send that request to your own server instead, do whatever you want over there and then return the results.
that is not the solution of problem .I must have to use this web service any how using java script only ,not by jquery or anything else
@KushalpalSingh you're asking how to do something impossible, then complaining when someone suggests an alternative? That seems short-sighted. But anyway 2 things: 1) jQuery is Javascript, and 2) you misspelled XMLHttpRequest.
@Dan thanx for response but till now i did't understand the problem,if i can't use this web service then what is the use of this web service. I can get responce when i call this using java.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.