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)