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);
}
Adam Wagner
16.2k7 gold badges54 silver badges67 bronze badges
asked Nov 12, 2011 at 4:41
iKushal
2,9992 gold badges27 silver badges20 bronze badges
1 Answer 1
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
answered Nov 12, 2011 at 4:45
hugomg
70.4k30 gold badges168 silver badges258 bronze badges
Sign up to request clarification or add additional context in comments.
7 Comments
iKushal
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...
hugomg
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.
iKushal
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
Dan
@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.iKushal
@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.
|
lang-js