1

I copied this ajax call from another one that works and I can't figure out why it's not successfull. Here is the code:

$.ajax({
    type: "POST",
    url: "addTune.php",
    data: {
        database: setlist,
        name: tune,
        orderno: orderno,
        midi: midi
    },
    error: function (e) {
        alert("The PHP Call failed!  hmmm");
        alert(e.status);
    },
    success: function (response) {
        alert(response);
    }
});

I get the error function every time. Are there any blaring typos or other stupid mistakes?

Edit: trying to chase down the error with:

$.ajax({

                type: "POST",
                url: 'addTune.php',
                data: {database : setlist, name : tune, orderno : orderno, midi : midi},
                error: function(e){
                    alert("The PHP Call failed!  hmmm");
                    alert(e.status);
                $.ajaxSetup({
                    "error": function(jqXHR, status, thrownError) {
                        alert('error');
                        var responseText = jQuery.parseJSON(jqXHR.responseText);
                        console.log(responseText);
                    }
                    });
                },
                success:  function(response){
                    alert(response);

                }



            });


        });

Update: I was just able to add a row with the command line. any thoughts as to what I can do to try and narrow this down further?

Loren Zimmer
  • 482
  • 1
  • 6
  • 29
  • 1
    What error do you get? – Marcus Mar 06 '13 at 17:45
  • You're getting the error function because the ajax call is failing, its not a javascript issue. Open up firebug or whatever and look at request/response. – Galen Mar 06 '13 at 17:47
  • `addTune.php` is this file present at same level? – Jai Mar 06 '13 at 17:47
  • @Jai yes, I double checked a couple times. – Loren Zimmer Mar 06 '13 at 17:50
  • @Galen I'm using chrome and am still learning the debug tools, do you have any experience with them? – Loren Zimmer Mar 06 '13 at 17:51
  • @WaleedKhan this past time it simply responded with "500" – Loren Zimmer Mar 06 '13 at 17:52
  • Open the debug tools before you make the ajax call (if call happens at page load, open tools and reload). then go to the network tab. here you can inspect the ajax call and see what the error returning is. – Ohgodwhy Mar 06 '13 at 17:53
  • @LorenZimmer Well then your PHP code is erroring. Turn on all the errors possible and check your server logs. – Waleed Khan Mar 06 '13 at 17:53
  • @LorenZimmer How are you testing it on local server or prod server? – Jai Mar 06 '13 at 17:57
  • @Jai I'm checking all of this on a client machine. I'm running this on a raspberry pi. – Loren Zimmer Mar 06 '13 at 18:04
  • @LorenZimmer `dataType` is missing. what are you expecting from that file? – Jai Mar 06 '13 at 18:04
  • @Jai Just to update a mysql database. Would I need a dataType for that? – Loren Zimmer Mar 06 '13 at 18:12
  • @LorenZimmer NO, Absolutely not! Now i think you have issues in php side. – Jai Mar 06 '13 at 18:21
  • @Jai I think its on the php side too. Now I just need to figure out how to figure out what that issue is.... – Loren Zimmer Mar 06 '13 at 18:37
  • @LorenZimmer You might look into how you are inserting the posted values. – Jai Mar 06 '13 at 18:41
  • In Firebug, right-click on the POST request's log, and open in new tab. From there, refresh after you make server-side changes until you get the right response. The fact that this is an AJAX request is just making it harder for you to focus on the problem. – landons Mar 06 '13 at 20:56
  • @landons It's almost like the page reloads and the php goes away before I can look at the errors in firebug – Loren Zimmer Mar 06 '13 at 22:38
  • If you want to see any error in the php create a .htaccess file and put this content: php_flag display_errors on php_value error_reporting 2039, see http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php – Guilherme Mar 13 '13 at 04:03

2 Answers2

0

i am no pro at this but maybe using single quote instead of double quotes? because i'm working on a project were i also have to do ajax calls and i use single quotes

i'm just suggesting something, not really good at this

Stijn De Schutter
  • 237
  • 2
  • 3
  • 13
0

If you get into the error callback then you have an error with the page you are calling and not with the js code. Check if the php page is reached. If it is check the php code if it returns a valid result.

From jquery DOCS.

error

Type: Function( jqXHR jqXHR, String textStatus, String errorThrown ) A function to be called if the request fails. The function receives three arguments: The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object, a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror". When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error." As of jQuery 1.5, the error setting can accept an array of functions. Each function will be called in turn. Note: This handler is not called for cross-domain script and JSONP requests. This is an Ajax Event.

Galen
  • 29,976
  • 9
  • 71
  • 89
Dumitrescu Bogdan
  • 7,127
  • 2
  • 23
  • 31