Timeout in JQuery $ .post by emulating $ .ajax
1 answer
$.POST
is a pre-installed version $.ajax
, so several parameters are already set.
Essentially, a
$.POST
equals
$.ajax({ type: 'POST', url: url, data: data, success: success, dataType: dataType });
But you can create your own submit function to send the request through $.ajax
at last.
Here is a custom POST plugin that I just coded.
(function( $ ){
$.myPOST = function( url, data, success, timeout ) {
var settings = {
type : "POST", //predefine request type to POST
'url' : url,
'data' : data,
'success' : success,
'timeout' : timeout
};
$.ajax(settings)
};
})( jQuery );
The custom POST function is now ready
Using:
$.myPOST(
"test.php",
{
'data' : 'value'
},
function(data) { },
5000 // this is the timeout
);
Enjoy :)
+5
source to share