using beforeSend and complete with $.post?

Viewed 45007

could one use the beforeSend() and complete() handlers with $.post or do you have to use $.ajax for it?

4 Answers

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
});

You could use $.ajaxSetup but it will apply globally. If this doesn't fit you you should use $.ajax.

Gotta use $.ajax, unless you use $.ajaxSetup(), but that may not be the wisest choice.

Any reason why you shouldn't use $.ajax?

Related