Pass The Same Options To A Jquery Function Over And Over
I use this jQuery Ajax-Request, which I configured for my needs: jQuery.ajax({ url: 'apiBridge.php?url=' + encodeURIComponent(url), headers: { 'Some Weird Header':
Solution 1:
Define a set of standard options:
var ajaxOpts = {
headers:{},
url:"someUrl",
complete:function(){//whatever;},otheroptions:"asneeded"
};
When you make each ajax call, extend the local options object with the standard options:
$.ajax($.extend({url:"custom", success:doAThing}, ajaxOpts));
...or as @gdoron says, use ajaxSetup
. I prefer $.extend because that way I'm not clobbering other $.ajax calls on the page I might not control.
Solution 2:
You can use the ajaxSetup function.
jQuery.ajaxSetup( options )
Description: Set default values for future Ajax requests.
Post a Comment for "Pass The Same Options To A Jquery Function Over And Over"