When the page is loaded, Ajax asynchronously requests data, $.each () traverses the data, and through jquery the data HTML () to the DOM structure.

Source: Internet
Author: User

A screenshot of an Ajax method in the actual combat project



Knowledge Point One: jquery initializes the page mode.

<script src= "Scripts/jquery-1.8.2.min.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
Alert ("First method.") ");
});
$ (function () {
Alert ("second method.") ");
});
JQuery (function ($) {
Alert ("Third method.") ");
});
Window.onload = function () {
Alert ("Fourth method. ");
}
</script>

Knowledge Point two: jquery traversal data Way

For In loop:

For In loop for 
    (x in Obj.bkdata) { 
        //x representation is subscript to specify the variable, the specified variable can be an array element, or it can be an object's property. 
        Console.log (obj.bkdata[x]); 
      

Element each method

if (obj.status = = 1) { 
        $ (obj.bkdata). each (function (index,item) { 
            //index refers to subscript//item refers to the 
            corresponding element content 
            // This refers to each element object 
            //console.log (Obj.bkdata[index]); 
            Console.log (item); 
            Console.log ($ (this));} 
    else{ 
        alert ("Wrong data ~"); 
    };  

Knowledge Point three: How to put values into the DOM structure through jquery.

Step one: Define a variable var str= "";

Step two: Mosaic DOM structure (pay attention to the use of escape characters, again do not explain)


Step three: Add the tiled DOM structure to the specified location. $. ("#id"). HTML (str)

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.