JavaScript gets multiple data (simulate AJAX fetch data) _javascript tips

Source: Internet
Author: User
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" > < HTML xmlns= "http://www.w3.org/1999/xhtml" > <pead> <title>guestbook demo</title> <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/> <meta name=" Author "content=" Sheneyan "/> <script type=" Text/javascript "> var data = [{id:11, Name: ' Passerby ', Mail: ' somebodyA@foo.com ', title: ' Test this message board with no ', content: ' Test is testing, do not ask me why the test, also don't ask me for what test, anyway, I was to measure Try, what can you do to me? ', Time: ' 2007-03-21 12:33:43 '}, {id:12, name: ' Passerby B ', Mail: ' somebodyB@foo.com ', title: ' Hello, trouble you one thing ', content: ' Hello, can you tell Sue me for your QQ? I have trouble with you ', Time: ' 2007-03-22 22:33:43 '}, {id:13, name: ' Passerby C ', Mail: ' somebodyC@foo.com ', title: ' Ah Ah ', content: ' The world is so beautiful , I am so grumpy, so bad ~ ~ ', Time: ' 2007-03-23 12:03:41 '}, {id:14, Name: ' Passerby Ding ', Mail: ' somebodyD@foo.com ', title: ' ... ', con Tent: ' Actually ... I'm an actress ', Time: ' 2007-03-23 22:04:08 '}, {id:15, name: ' xxx ', Mail: ' Armya@fOo.com ', title: ' xxx ', content: ' Long night no new sleep, Yi, how sir you also did not sleep? ', Time: ' 2007-03-24 11:12:55 '}]; function Getmutlidata () {var x = p = document.getElementById (' post '); for (var i = 0; i < data.length i + +) {var o = P.clonenode (true); if (x.nextsibling) X.parentnode.insertbefore (o,x.nextsibling); else X.parentnode.appendchild (o); var t = o.innerhtml; t = t.replace (/<!--{(. *?)} -->/g,function (a,b) {var v = ""; try{v = eval ("data[" +i+ "]." +B); catch (e) {} return v; }); o.innerhtml = t; x = o; } p.style.display= ' None '; } </script> </pead> <body> <div id= "POST" > <fieldset> <legend id= "Post_header" > ( <!--{id}-->) ' ><!--{name}--> in <!--{time}--> published:</legend> <p id= ' Post_title ' ><! --{title}--></p> <p id= "post_content" ><!--{content}--></p> </fieldset> </div > <button onclick= "getmutlidata ()" > Get multiple data (simulate AJAX fetch data) </button> </body> </pTml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

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.