【发布时间】:2012-10-07 20:39:33
【问题描述】:
我是 jquery 新手,不知道从另一个域(跨域)获取 json 数据。
function createCORSRequest(method, url){
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr){
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined"){
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
xhr = null;
}
return xhr;
}
var request = createCORSRequest("get", "http://www.stackoverflow.com/");
if (request){
request.onload = function() {
// ...
};
request.onreadystatechange = handler;
request.send();
}
我从这里Ways to circumvent the same-origin policy找到了这个程序
也就是说通过上面的代码我们可以访问跨域的json数据。
我复制了代码。这是说处理程序是未定义的
我不知道如何定义处理程序。
我也不知道在 request.onload 里面写什么
我将在哪里得到 json 结果
请帮忙
提前致谢
【问题讨论】:
标签: asp.net jquery cross-domain