Reputation: 79756
could one use the beforeSend() and complete() handlers with $.post or do you have to use $.ajax for it?
Upvotes: 25
Views: 47998
Reputation: 91
This will work for complete:
var jqxhr = $.post("example.php", function() {
alert("success");
jqxhr.complete(function(){ alert("second complete"); });
For beforeSend, you'll have to use $.ajaxSetup before calling $.post if you don't want to use $.ajax as they said before.
Upvotes: 9
Reputation: 630509
You have 2 options, use $.ajax()
or $.ajaxSetup()
.
Using $.ajax():
$.ajax({
type: 'POST',
url: url,
data: data,
success: success
dataType: dataType
});
Or, before your post run $.ajaxSetup(), but this affects all ajax requests:
$.ajaxSetup({
beforeSend: myFunc,
complete: myCompleteFunc
});
Upvotes: 44
Reputation: 9055
Gotta use $.ajax, unless you use $.ajaxSetup(), but that may not be the wisest choice.
Any reason why you shouldn't use $.ajax?
Upvotes: 3
Reputation: 1038990
You could use $.ajaxSetup but it will apply globally. If this doesn't fit you you should use $.ajax.
Upvotes: 4