JQuery Ajax: Some details and how the main function expands

Source: Internet
Author: User
Tags extend

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;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.