Today I have heard that the success-Parameter in the jQuery.ajax function is deprecated. Have I understood that correctly? Or am i missunderstanding something?
For Example this would not work in the future:
$.ajax({ url: 'ax_comment.php', type: 'POST', data: 'mode=view¬e_id='+noteid+'&open='+open+'&hash='+hash, success: function(a) { ... } });
And i have to use this?
$.ajax({ url: 'ax_comment.php', type: 'POST', data: 'mode=view¬e_id='+noteid+'&open='+open+'&hash='+hash, success: function(a) { ... } }).done(function(a){.....};
Source: http://api.jquery.com/jQuery.ajax/ (Scroll down to Deprecation Notice)
ajax function is deprecated.
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.
version added: 1.0.Whenever an Ajax request completes with an error, jQuery triggers the ajaxError event. Any and all handlers that have been registered with the . ajaxError() method are executed at this time.
What is AJAX success? AJAX success is a global event. Global events are triggered on the document to call any handlers who may be listening. The ajaxSuccess event is only called if the request is successful. It is essentially a type function that's called when a request proceeds.
There is a difference between, the Ajax success callback method:
$.ajax({}).success(function(){...});
and the Ajax success local callback event (i.e., the Ajax parameter and property):
$.ajax({ success: function(){...} });
The success callback method (first example) is being deprecated. However, the success local event (second example) is not.
Local events are Ajax properties (i.e., parameters). The jQuery docs further explain that the local event is a callback that you can subscribe to within the Ajax request object.
So in future, you may do either:
$.ajax({}).done(function(){...});
or
$.ajax({ success: function(){...} });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With