jquery ajax调用mysql

I have found many threads regarding this issue, but unfortunately I couldn't get it running. Problem is I don't know much about JQuery.

I am trying to make an Ajax call using JQuery in order to fetch multiple records from a mysql database. I have the following function :

function updateWebpage () 
{
$.ajax({                                      
url: './sale/api.php',                  //the script to call to get data          
data: "",                  //you can insert url argumnets here to pass to  api.php
                                   //for example "id=5&parent=6"
  dataType: 'json',                //data format      
  success: function(rows)          //on recieve of reply
  {
        for (var i in rows)
        {
          var row = rows[i];          

          var username = row[0];
          var stateId = row[1];
          $('#output').append("<b>id: </b>"+username+"<b> stateId: </b>"+stateId)
                      .append("<hr />");
        } 
    } 
});

};

My api.php is executing a mysql query with something like this:

$array = retrieveUsersInfo('%');                          //fetch result    
echo json_encode($array);

My main issue, is how to debug an issue like this? Since ajax is calling asynchronously another file, I cannot view any errors. From my firefox debugger, I can see that the $.ajax function is entered, but success is not.

Thanks in advance.

a couple things to try.

  1. hit the api url directly in a browser (not through ajax) and make sure it returns the valid response.
  2. add an error: function(err){} to your jquery ajax call. this method will get called if there is something other than a 200 response back from the server.
  3. I use Chrome's developer tools more than firefox/firebug. It has a Network tab in it that shows me all the communication between the client and the server. You should see a call out to your api in that tab.

just off hand, i think you need to make sure the mime-type is set to text/json in your php file.