"Summarize" JSON data request simplified version of Understanding (the results of the Brother Kee)

Source: Internet
Author: User

Create a new. txt file under the homologous JS directory

{"  News": [    {"title": "Audit Management", "Time": "2018-03-10 21:00"},    {"title": "Menu Management", "Time": "2018-03-10 21:00"},    {"title": "Order Management", "Time": "2018-03-10 21:00"},    {"title": "Contract Management", "Time": "2018-03-10 21:00"},    {"title": "Logistics Management", "Time": "2018-03-10 21:00"},    {"title": "Administration", "Time": "2018-03-10 21:00"},    {"title": "Personnel Management", "Time": "2018-03-10 21:00"},    {"title": "Shopping Management", "Time": " 2018-03-10 21:00 "},    {" title ":" Wholesale Management "," Time ":" 2018-03-10 21:00 "},    {" title ":" Security Management "," Time ":" 2018-03-10 21:00 "},    {" title ":" Account Management "," Time ":" 2018-03-10 21:00 "},    {" title ":" Financial Management "," Time ":" 2018-03-10 21:00 "},    {"title": "Other Management", "Time": "2018-03-10 21:00"}  ]}
<!DOCTYPE HTML><HTML>    <Head>        <MetaCharSet= "Utf-8" />        <title>News</title>        <Linkrel= "stylesheet"href= "Css/index.css" />        <Scriptsrc= "Js/jquery.js"></Script>        <Script>$ (document). Ready (function(){                  varresult=$.ajax ({URL:"./newsdata.txt", Async:false, DataType:"JSON"                  }); Result=$.parsejson (result.responsetext);//convert to JSON format                  varNews=result.news; varHtmlobj= "';  for(varI=0; I<News.length;i++){    //Loop Build ListHtmlobj+= '<li class= "NewsItem" >'+News[i].title+'<span>'+News[i].time+'</span></li>'; }                  $('. Newslist'). HTML (htmlobj); //Replace the content in the HTML            }); </Script>    </Head>    <Body>        <H2>News</H2>        <ulclass= "Newslist">                    </ul>    </Body></HTML>

JS only single thread

Synchronization: Wait for the interface data to return and then go down one line to execute

Async: Put this request in the first place, go down.

JS single-threaded, one line down execution (synchronous), but if the interface is requested, the interface will delay the return of data,

This time if asynchronous, you can avoid waiting too long, directly execute the following code

But when he executes the following code, what does it take to get the data?

So, there's the callback function.

The callback function is what you do after you request the data asynchronously.

You can write in the callback function what you're going to do when you get the data.

"Summarize" JSON data request simplified version of Understanding (the results of the Brother Kee)

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.