Jquery page Initialization is commonly used in three ways, and Jquery sends ajax requests, jqueryajax

Source: Internet
Author: User

Jquery page Initialization is commonly used in three ways, and Jquery sends ajax requests, jqueryajax

First

$ (Document). ready (function (){

// Document readiness event

});

The second is the first simple method, which is equivalent to the first method.

$ (Function (){

// Document loading event, which is executed after the entire document is loaded. You only need to load all the DOM structures and execute the js effect before the browser puts all the HTML into the DOM tree. Including before loading external images and resources.

});

Third

JQuery (function ($ ){

});

 

Window. onload = function (){

// Onload event is the code onload event in js that occurs when the HTML is read, the DOM tree is generated in the memory, and the onload event occurs only after the three things of page rendering are completed. After all the documents on the entire page are loaded, execute. Unfortunately, this method not only requires that the DOM tree of the page be fully loaded, but also requires that all external images and resources be fully loaded. Unfortunately, if external resources and sample files take a long time to load, this js effect will make the user feel ineffective.

}

 

Simplified syntax window. onload is not simplified syntax $ (document). ready (function () {}) can be abbreviated to $ (function (){});

The $ symbol is a commonly used "selector" in the JS library. For example, $ in JQuery is the abbreviation function of Selector. For example, $ (this) is the meaning of "select now.

$. Ajax ({

Url: "request address ",

Type: "request method ",

Data: "Request Parameters ",

DataType: "server return data type ",

Success: "The callback function corresponding to normal server processing ",

Error: "callback function corresponding to server error"

});

 

The Code var url =$ ("# id") is displayed today "). attr ("menu-url"); I always thought it was adding attributes to the node. I haven't figured it out for a long time. It turns out to be an incorrect understanding. If two parameters are passed in attr, the attribute is added to the node. If there is only one parameter, the node content is obtained. Or I didn't understand it correctly at the beginning. Do not take it for granted.

 

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.