How can I modify the default values of options for the $.ajax()
function?
Ideally to do something similar to:
//set ajax async to false
$(someSelector).load(url, data, function(){});
//set ajax async to true
to allow me to carry out .post()
synchronously.
This is an Ajax Event. When sending data to the server, use this content type. Default is "application/x-www-form-urlencoded; charset=UTF-8", which is fine for most cases.
The ajax() method is used to perform an AJAX (asynchronous HTTP) request. All jQuery AJAX methods use the ajax() method. This method is mostly used for requests where the other methods cannot be used.
The ajaxSetup() method in jQuery is used to set the default values for future AJAX requests. Syntax: $.ajaxSetup( {name:value, name:value, ... } )
global: It's default value is true. It is used to specify whether or not to trigger global AJAX event handles for the request. ifModified: It's default value is false. It is used to specify whether a request is only successful if the response has changed since the last request.
Try using $.ajaxSetup()
$.ajaxSetup({
async: false
});
You want ajaxSetup
$.ajaxSetup({
url: "/xmlhttp/",
global: false,
type: "POST"
});
$.ajax({ data: myData });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With