The Jquery.ajax function is explained in the previous article. This article supplements some other details. The next article begins by explaining how JQuery can load the script dynamically, XMLHttpRequest, and Jsonp into the Jquery.ajax.
Jquery.ajaxsetup
We can see from the main function that the parameters are generated by Jquery.ajaxsetup:
Transforming Parameter objects through Jquery.ajaxsetup
s = Jquery.ajaxsetup ({}, Options),
So what's jquery.ajaxsetup doing?
Jquery.ajaxsetup = function (target, settings) {
//If there is a parameter return
settings?
Create a Settings object, first put the jquery.ajaxsettings attributes in,
//And then put the parameters in
ajaxextend (Ajaxextend (target, jquery.ajaxsettings), Settings):
//And puts the properties of the setting object into the Jquery.ajaxsettings object
ajaxextend (jquery.ajaxsettings, target);
Ajaxextend
There are some differences between ajaxextend and jquery.extend to avoid deep replication of properties that do not require deep copying.
function ajaxextend (target, src) {
var key, deep,
flatoptions = JQuery.ajaxSettings.flatOptions | | {};
Traversing all key for Src objects
{
//If the value is not undefined if
(src[key]!== undefined) {
//judgment is not required for deep copying , if no deep copy is required, write the attribute directly into target,//otherwise write it in deep///
we can see it from jQuery.ajaxSettings.flatOptions//
In fact, the URL and context (flatoptions[key] is not required for deep copying.
target: (Deep | | (deep = {})) ) [Key] = src[key];
}
If deep is not undefined, proof requires deep copy if
(deep) {
//start deep copy
Jquery.extend (true, target, deep)
;
Returns target return
target;