2

I have a javascript function that makes an ajax call to a PHP page for some database transactions and data processing. Here is the function:

function processQuizResults()
{
    console.log("Processing results...");

    var selections = [];
    for (var i = 1; i <= 8; i++)
    {
        var thestr = "#sel" + i;
        $(thestr).is(':checked') ? selections.push(1) : selections.push(0);
    }

    var URLcode = '<?php echo $URLcode; ?>';
    var ajaxURL = "/processNewData.php?qid=" + URLcode + "&res=";
    for (var i = 0; i < 8; i++)
    {
        ajaxURL += selections[i];
    }

    $.ajax({
        url: ajaxURL,
        type: 'post'
    })
    .done(function () {
        console.log("ajax success.");
    })
    .fail(function () {
        console.log("ajax failure.");
    });
}

In Chrome, the browser makes the Ajax call, I see the breakpoints in my processNewData.php get hit (if I have some set) in visual studio, and the data comes out clean and showing up in my database properly on the other side. However, in firefox, running this exact same function has the $.ajax go into its .fail method, and the processNewData.php code never gets executed.

I have no idea how to debug an issue such as this and I have no idea what could be causing the problem. Can anyone kindly tell me where I'm going wrong?

jros
  • 714
  • 1
  • 10
  • 33
  • With firefox developer tools or firebug (firebug have better network errors and warnings messages in my opinion) you can see the ajax request on the console and then click on it and maybe it will give you some information (bad url, method not found, data not found or something) or event the "post" could be in "POST" (weird about the POST thing, once I came with that error) – Jorge F Aug 23 '15 at 21:48
  • @JorgeF http://i.imgur.com/3jbiVm0.png – jros Aug 23 '15 at 22:08
  • Can you add parameters given to your `.fail()` method and post their values here? Your callback method will receive 3 parameters: http://stackoverflow.com/a/9847328/237073 – Martin Wiboe Aug 23 '15 at 22:28
  • @MartinWiboe The testStatus and errorThrown come back as "error" and (an empty string) respectively. jqXHR comes back as the following object: http://i.imgur.com/UG4FUIF.png – jros Aug 23 '15 at 23:55
  • What is the full URL of the containing page and script? Is there anything else in the console? – Ry- Aug 24 '15 at 01:36
  • @minitech the page the ajax request is being called from is `http://localhost:14602/quiz.php?qid=XaXRXRrCsZ` and the page the ajax request is calling to is `http://localhost:14602/processNewData.php?qid=XaXRXRrCsZ&res=10000000` – jros Aug 24 '15 at 01:42
  • Do you have any extensions installed in Firefox, or settings changed in `about:config`? Try disabling/resetting them temporarily. – Ry- Aug 24 '15 at 01:47
  • @minitech It's in out-of-the-box settings as I never use FF except for testing all browsers for my projects. – jros Aug 24 '15 at 02:11
  • `.fail(function (error) { console.log(error); }); ` use this code to find the error in console – J Santosh Aug 24 '15 at 04:30
  • Does not look like CORS-related ... Chrome might have issues with CORS as well, though. Eventually you might exclude CORS issue by adding related headers in PHP script processNewData.php.According to comment of Jorge F try using the tab labelled "Net" and maybe show response rather request stuff if any is available. Just a poorman's debugging question: what happens if you paste the request URL as logged into address bar or try open it in another tab? – Thomas Urban Aug 24 '15 at 21:17

1 Answers1

0

According to this answer you're probably running into CORS issues.

From what domains are you serving the server-side app and the front-end? Try to make sure they're on the same domain and see if you get the same error.

Community
  • 1
  • 1
Martin Wiboe
  • 2,119
  • 2
  • 28
  • 50