1
votes

Below is my piece of code. My issue is the function on success never gets called. It always throws the error section.

$.ajax({ 
   url: 'http://localhost/zd/get_list',
   data: 'term=' + medical_provider, 
   dataType: 'json', 
   type: 'GET',
   success: function(data){
      alert('success');
   },
   error:  function(jqXHR, textStatus, errorThrown){
       alert(jqXHR);
  }
});

when i alert jqXHR is get [object Object] and when I alert textStatus I get "error" and when I alert errorThrown I get a blank error message. I am using jquery 1.11.0. I never get the success alert. Your help is greatly appreciated.

Also the the data returned in json is properly validated. I did a test on jsonlint.

2
Use the browser's debugging tools to watch the network traffic and see exactly what is sent and received. - Jeremy J Starcher
console does not throw any errors. Shows status 200 for the called url - Ela Buwa
Maybe your server isn't responding with the json callback? Check to make sure it is indeed passing back that variable which ajax passes with each call you make. If the script doesn't receive the callback id it sent out, it won't process the results being fed back in through JSON. One quick way to check, would be to change dataType to 'text', and alert('success') to alert(data) to see what the server is passing back. - DoctorLouie
I checked the chrome network section in the developer tools. Funny thing, it throws status (canceled) instead of 200. Any ideas guys? When I open the Network Path in the console in a new tab, the json feed gets displayed. Any help is greatly appreciated. - Ela Buwa
I have updated my answer with something to try - Starscream1984

2 Answers

2
votes

Your get_list server-side functionality is erroring.

Use chrome developer tools to breakpoint and inspect your jqXHR object in the error callback, it will have more details about what is going wrong.

Edit:- based on your updated comments, try adding:

contentType: 'application/json',

to your ajax call parameters

1
votes

So it turns out, the base url (was using codeigniter) was my computers ip address instead of localhost. Accessing the through the ip addy OR changing the base url to localhost worked. Thank you all for the help.