I have written a web application which uses lot\'s of $.post
calls with JQuery. Now I would like to send withCredentials: true
with it to keep a sessio
You can use jQuery.ajaxSetup() to set default options that each ajax request will use (including $.post
and $.get
)
$.ajaxSetup({
crossDomain: true,
xhrFields: {
withCredentials: true
},
username: 'test',
password: 'test'
});
$.post('http://example.com/server/api.php', {
username: 'test',
password: 'test'
}, function (d) {
$('body').html(d.status);
}, 'json');
Also the warning regarding this API
Note: The settings specified here will affect all calls to $.ajax or Ajax-based derivatives such as $.get(). This can cause undesirable behavior since other callers (for example, plugins) may be expecting the normal default settings. For that reason we strongly recommend against using this API. Instead, set the options explicitly in the call or define a simple plugin to do so.
from jQuery documentation