[webkit-help] XHR Level 2 not working with 302 ?

Nicolas Ramz nicolas.ramz at gmail.com
Fri Sep 10 02:05:10 PDT 2010


Hello,

I'm sorry if this isn't the correct place to ask for this, but I couldn't
find some forum to ask for this...

I started using XHR Level 2 (Cross-Origin) and I'm having problems with
redirections (302).

Here is what I'm doing:

The client is doing the following request:

====
var req = new XMLHttpRequest();
req.open('GET', 'http://www.server1.com/index.php', true);

req.onreadystatechange = function (aEvt)
{
if (req.readyState == 4)
{
if (req.status == 200)
{
console.log(req.responseText);
}
else
{
console.log('oops');
console.log("Error loading page, status=", req.status);
}
}
};

req.send(null);
====

http://www.server1.fr/index.php contains the following code:

====
<?php
header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Methods: GET, POST');
header('Location: http://www.server2.fr/index.php');
?>
====

http://www.server2.fr/index.php contains the following code:

====
<?php
header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Methods: GET, POST');
?>
<div>foo</div>
====

I tried with Safari ( AppleWebKit/533.16 (KHTML, like Gecko) Version/4.0.5
Safari/531.22.7), and it seems the 302 doesn't work at all with it (both GET
and POST fail when using redirect). However when returning data from server1
(that is without using a 302 redirection), it works.

What could be wrong ? Is 302 supported using Cross-Origin ? Maybe some more
headers need to be added ?

I couldn't find information about 302 on the W3C specs website.

Thanks.
-- 
PS: I tried the same code with Firefox 3.6.9 (which supports XHR Level 2 as
well), and 302 redirects work, but only when using GET method. When using a
POST instead it fails, like in Webkit.
--
Nicolas Ramz - Développeur Web
Tél: 06-84-35-08-88
--
http://www.warpdesign.fr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-help/attachments/20100910/255b09b8/attachment.html>


More information about the webkit-help mailing list