Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deprecation of success Parameter in jQuery.ajax?

Tags:

jquery

ajax

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&note_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&note_id='+noteid+'&open='+open+'&hash='+hash,             success: function(a) {             ...              }         }).done(function(a){.....}; 

Source: http://api.jquery.com/jQuery.ajax/ (Scroll down to Deprecation Notice)

like image 206
Reflic Avatar asked Apr 04 '13 20:04

Reflic


People also ask

Is AJAX successful deprecated?

ajax function is deprecated.

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 jQuery AJAX fail?

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 success function AJAX?

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.


1 Answers

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(){...} }); 
like image 113
Steve Avatar answered Sep 17 '22 12:09

Steve