jQuery .ajax() request to PHP proxy not recieving echoed value (FIREFOX ONLY)

The following code works perfectly in Chrome and Safari, but bonks in Firefox.

First the javascript:

$.ajax('/sn.php',{
    type: 'POST',
    dataType: 'json',
    data: {...stuff},
    complete: function(response){
        console.log(response);
        // do stuff with response...
    }
});

and the php relay (on MY server) that uses cURL() to POST or GET from another domain:

// setup cURL...
$token = curl_exec($handle);
echo $token;
error_log('token='.$token);

$token shows up perfectly in the error_log, and everything works perfect in Chrome and Safari, but in Firefox the ajax status is "error" and the responseText is blank. Been banging my head against the wall for a couple days on this one.


Firefox doesn't have a native console.log like Webkit browsers do. Comment that out or replace it with alert() and I bet it works.


I might be barking up the wrong tree here, but I suspect it's the call to error_log in your php code. If you remove that, does it help?

Also, it might help to set an error handler on your .ajax request too, something like

$.ajax('/sn.php',{
    type: 'POST',
    dataType: 'json',
    data: {...stuff},
    complete: function(response){
        console.log(response);
        // do stuff with response...
    },
    error: function (jqXHR, textStatus, errorThrown){
        console.dir(jqXHR);
        console.log(textStatus);
        console.log(errorThrown);
    }
});

It won't fix the problem, but it'll at least give you some more debug output to look at

edit Couple more ideas from 249692. Is your webserver returning the correct mime type for the request? Can you try doing a beforeSend and setting overrideMimeType


Firefox was returning Status: 0 for the ajax request. Based on a heads up from this blog post I updated my form to onSubmit='return false;' and now it works perfect.

链接地址: http://www.djcxy.com/p/46110.html

上一篇: AJAX调用不在jQGrid中工作

下一篇: jQuery .ajax()请求到PHP代理不接收回显值(FIREFOX ONLY)