I would like to set a global data parameter for all my ajax requests
$.ajaxSetup({
data: {hash : "12345"}
});
after setting this I call:
var myData = {
name : "John",
age : "28"
}
$.get(url, myData, function(data){
...
});
this works fine and add all 3 parameters (hash, name, age) to request data
but when I call load function instead of get, it doesnt work and I get only 2 parameters (name, age):
$("#my_div").load(url, myData, function(data){
...
});
please could anyone tell me why it doesnt work for load function? I have many usages of load function in my app and I dont want to change load on get
thank you for every tip!
This could be considered a bug in jQuery; or at the very least, they should accept the interface between their AJAX methods are inconsistent.
The only way to fix this is by using
jQuery.extendto merge the defaultdatawith thedatayou’ve provided:Before making the request.
How its a bug:
loadconverts thedataobject into a string before passing in onto the underlyingjQuery.ajaxmethod, where asgetdoesn’t.Because of this, when
ajaxExtendbuilds thedataobject, in theloadscenario thedataparameter is set to the string, whereas withgetthedataobject is merged withjQuery.ajaxSettings.