jQuery deferred method and ajax beforeSend()

Viewed 1834

By using the deferred object in $.ajax

  • the success-callback can replaced by the deferred-method done()
  • the error-callback acn replaced by the deferred-method fail()
  • and the complete-callback can by replaced by always()

by using

var jqxhr = $.ajax({
                url: Config.baseUrl+"/ajax/favourites/set-favourite.ajax",
                dataType: "json",
                data: attrs,
                type: "POST",
                beforeSend: function(){
                    console.log("before send");
                }
            });

how can i implement the beforeSend-callback by using the deferred object?

why i don't use the beforeSend-callback inside the $.ajax function? Because the request is inside a Model-Instance (http://canjs.com/docs/can.Model.model.html#section_Non_standardServices) so the model object do the request and all the other suff, like manipulate the DOM will done in the deferred object. i would like to manipulate the DOM before sending the ajax request.

how could i do that?

1 Answers
Related