views:

429

answers:

2

Hi all,

I use the following code to get some json data:

var request = new Request.JSON(
    {
        'url':        sourceURI,
        'onSuccess':  onPageData
    }
);
request.get();

Request.JSON is a class from Mootools (a javascript library).

But on linux (ubuntu on firefox 3.5 and Chrome) the request always fails. So i tried to display the http request ajax is sending. (I used netcat to display it)

The request is like this:

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

The HTTP request (first line) is not how it should be:

OPTIONS /the+url HTTP/1.1

It should be:

GET /the+url HTTP/1.1

Does anybody know why this problem is and how to fix it?

Edit:

The ajax request gets the following result from my Apache server:

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

The content-length should not be zero. But i think, the Request.JSON module whould now see that the GET request is available and can use it?

A: 

I have no idea why the request header would change, but the Request classes offer more functionality to send a request. Try send() instead of get();

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

Or bind it to the Request at once;

var req = new Request.JSON({
    method: 'get',
    ...
}).send();
Björn
+1  A: 

This may have to do with the W3C Cross-Origin Resource Sharing spec.

Julian Reschke
I fixed it, thanks! In apache i enabled the mod_headers and added a config file in conf.d wich says: Header set Access-Control-Access-Origin "*" This line accept all request from all domains (somethink like the crossdomain.xml for flash).
VDVLeon