我使用以下代码获取一些JSON数据:
var request = new Request.JSON(
{
'url': sourceURI,
'onSuccess': onPageData
}
);
request.get();
json是来自mootools(一个javascript库)的类。
但是在Linux(火狐3.5和Chrome上的Ubuntu)上,请求总是失败。所以我尝试显示Ajax发送的HTTP请求。
(我用netcat显示)
请求如下:
OPTIONS /the+url HTTP/1.1
Host: example.com
Connection: keep-alive
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/532.3 (KHTML, like Gecko) Chrome/4.0.226.0 Safari/532.3
Referer: http://example.com/ref...
Access-Control-Request-Method: GET
Origin: http://example.com
Access-Control-Request-Headers: X-Request, X-Requested-With, Accept
Accept: */*
Accept-Encoding: gzip,deflate
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
HTTP请求(第一行)不应该是这样的:
OPTIONS /the+url HTTP/1.1
应该是:
GET /the+url HTTP/1.1
有人知道这个问题的原因和解决方法吗?
编辑:
Ajax请求从我的Apache服务器获得以下结果:
HTTP/1.1 200 OK
Date: Fri, 23 Apr 2010 08:09:41 GMT
Server: Apache/2.2.15 (Debian)
Allow: GET,HEAD,POST,OPTIONS
Content-Length: 0
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/plain
内容长度不应为零。但是我认为,request.json模块现在可以看到get请求是可用的,并且可以使用它吗?