Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery.ajax success callback function not executed

I have a JavaScript Ajax call (jQuery.ajax), that does not execute the success callback function.

$.ajax({         url: target,         contentType: 'application/json; charset=utf-8',         type: 'POST',         // type: 'GET',         dataType: 'jsonp',         error: function (xhr, status) {             alert(status);         },         success: function (result) {             alert("Callback done!");             // grid.dataBind(result.results);             // grid.dataBind(result);         }     }); 

I see in firebug, that the request is posted and the correct result in terms of the json is returned as expected. What is wrong?

like image 248
Frank Michael Kraft Avatar asked May 07 '10 08:05

Frank Michael Kraft


People also ask

Why is ajax success not working?

ajax post method. The reason was my response was not in the JSON format so there was no need for the dataType: 'json' line in the submit method. In my case, the returned response was in text format that's why it was not going to success event. Solution: Remove dataType: 'json' line.

What triggers ajax success?

Whenever an Ajax request completes successfully, jQuery triggers the ajaxSuccess event. Any and all handlers that have been registered with the . ajaxSuccess() method are executed at this time. $( ".

How do I return data after ajax call success?

You can store your promise, you can pass it around, you can use it as an argument in function calls and you can return it from functions, but when you finally want to use your data that is returned by the AJAX call, you have to do it like this: promise. success(function (data) { alert(data); });

Is ajax successful deprecated?

ajax function is deprecated.


1 Answers

For many times I have encountered similar problems and most of the time the reason was a malformed json. Try getting the result as text data type to see whether this is your problem.

Also, I'd like to ask if you're using a parameter like "&jsoncallback=?" in your url, since your data type is jsonp instead of simple json.

like image 106
Cagdas Avatar answered Sep 20 '22 23:09

Cagdas