2

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.

SunnyRed
  • 3,214
  • 3
  • 32
  • 54
brittohalloran
  • 3,284
  • 4
  • 25
  • 26

3 Answers3

1

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

Community
  • 1
  • 1
Dan F
  • 11,555
  • 3
  • 43
  • 68
  • Good stuff - didn't even know about console.dir. (1) tried removing error_log, didn't fix it (2) added error status logging, and got: readyState: 0, responseText: "", status: 0, and statusText: "text". nothing too revealing there (3) looking into mime type right now, brb – brittohalloran Jul 31 '11 at 02:51
  • Tried setting mime type ('application/json') with beforeSend, didn't work. Also tried setting the mime type in PHP with header('Content-Type: application/json'), to no avail. Good ideas though. Looks like Firefox is more sensitive to mime type errors than the webkit browsers. – brittohalloran Jul 31 '11 at 03:22
1

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.

evan
  • 4,039
  • 1
  • 15
  • 17
  • Tried it - no dice. Messages sent to console.log() DO work (I have firebug installed), but good thinking. Any differences between Chrome and Firefox are going to be where the trouble is. – brittohalloran Jul 31 '11 at 02:46
1

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.

brittohalloran
  • 3,284
  • 4
  • 25
  • 26