Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using beforeSend and complete with $.post?

Tags:

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

like image 517
ajsie Avatar asked Feb 13 '10 15:02

ajsie


3 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 }); 
like image 170
Nick Craver Avatar answered Sep 22 '22 15:09

Nick Craver


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.

like image 35
kruonx Avatar answered Sep 23 '22 15:09

kruonx


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

like image 36
Darin Dimitrov Avatar answered Sep 23 '22 15:09

Darin Dimitrov