Ela Buwa
Ela Buwa

Reputation: 1704

jquery ajax always throws error (never becomes success)

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.

Upvotes: 1

Views: 1389

Answers (2)

Ela Buwa
Ela Buwa

Reputation: 1704

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.

Upvotes: 1

Starscream1984
Starscream1984

Reputation: 3062

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

Upvotes: 2

Related Questions