【发布时间】:2011-01-04 12:57:36
【问题描述】:
问题:
我正在尝试跨域使用 JSON,但我发现的只是 JSON 解析器,我不需要...
我读过可以使用 JSON 进行跨域请求,
但到目前为止,我所看到的只是使用 XMLHttpRequest 的实现...
- 这意味着您不能使用跨域请求,至少不能在 IE 8 之外使用......
我一直在http://www.json.org/,但我发现的只是解析器或无用的。
到目前为止,我在谷歌上找到的最好的是
http://devpro.it/JSON/files/JSONRequest-js.html
但这相当混乱,不能跨域工作,也不能在域内工作 - 或者根本不工作......
var the_object = {};
var http_request = new XMLHttpRequest();
http_request.open( "GET", url, true );
http_request.onreadystatechange = function () {
if ( http_request.readyState == 4 && http_request.status == 200 ) {
the_object = JSON.parse( http_request.responseText );
}
};
http_request.send(null);
【问题讨论】:
-
如果您使用“http_request.responseXML”,那么如果您从服务器的响应不是 XML,它将变为 null。
标签: javascript json xmlhttprequest