代码之家  ›  专栏  ›  技术社区  ›  VDVLeon

Linux Ajax(mootools request.json)头错误

  •  1
  • VDVLeon  · 技术社区  · 14 年前

    我使用以下代码获取一些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请求是可用的,并且可以使用它吗?

    2 回复  |  直到 14 年前
        1
  •  2
  •   Julian Reschke    14 年前
        2
  •  0
  •   Björn    14 年前

    我不知道请求头为什么会改变,但是请求类提供了更多发送请求的功能。尝试send()而不是get();

    var req = neq Request.JSON({...});
    req.send({
        'method': 'get'
    });
    

    或者立即将其与请求绑定;

    var req = new Request.JSON({
        method: 'get',
        ...
    }).send();