1

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.

5
  • Use the browser's debugging tools to watch the network traffic and see exactly what is sent and received. Commented Apr 12, 2014 at 11:33
  • console does not throw any errors. Shows status 200 for the called url Commented Apr 12, 2014 at 11:35
  • 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. Commented Apr 12, 2014 at 11:37
  • 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. Commented Apr 12, 2014 at 11:44
  • I have updated my answer with something to try Commented Apr 12, 2014 at 12:06

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

You should accept your own answer to get it to the top
yeah i should. I lost track when SF wanted me to stay away for 1 day before accepting my own answer. :D

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.