【发布时间】:2013-03-01 09:35:29
【问题描述】:
我需要使用 $.getJSON 访问从另一台机器(跨域请求)获得的响应消息的大小,虽然我可以在 chrome 控制台中看到请求和响应,但它不起作用。这是我的请求代码:
xhr=$.getJSON('http://192.168.1.102/server/server.php?callback=?',
{data:array}, function(res){
alert(xhr.getAllResponseHeader());
},
type='json');
运行时出现“Uncaught TypeError: Object # has no method 'getAllResponseHeader'”错误。当我使用
alert(xhr.getResponseHeader("Content-Length"));
我得到“空”。
请考虑我使用的是跨域获取。
【问题讨论】:
-
正确的方法名是
getAllResponseHeaders。 -
对于跨域,它可能使用JSONP。他们的医生说
However, since JSONP and cross-domain GET requests do not use XHR, in those cases the jqXHR and textStatus parameters passed to the success callback are undefined. -
1- @Andrei :谢谢你的“s”,当我提醒 xhr.getAllResponseHeaders();它什么也不返回,甚至不返回null。
-
你在 res 中得到什么了吗?
-
@HungryCoder 那么解决方案是什么?我们可以在javascript和php中自己计算bts吗?
标签: javascript rest jquery