问题是,当我想从服务器获得响应时,它会给出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);
}
答案 0 :(得分:4)
除非您的网页已经从www.google.com域投放,否则您无法对www.google.com进行AJAX调用。
https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript