Use JS to read the Dynamic Web site data returned from the server side

Source: Internet
Author: User
Tags html page json

  This article mainly introduces the use of JS read Dynamic Web site from the server side of the data returned, the need for friends can refer to the following

Use JS in HTML to read the Dynamic Web site returned from the server data display     1, js.html page     need to introduce the implementation of jquery JS file   Copy code code as follows: <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >  <HTML>  <HEAD>  <title > New Document </TITLE>  <meta name= "generator" content= "EditPlus" >  <meta name= "Author" Content= "" >  <meta name= "Keywords" content= "" >  <meta name= "Description" content= "" >  <script src= "Jquery-1.8.2.min.js" ></script>    <script>    $ (function () {  //$ ("#loaddata"). Click (function () {  $ (document). Ready (function () { //Read JSON data using the Getjson method, / /Note: Info.json can be a different type of file, as long as the data is JSON type   $.getjson (' Info.json ', function (data) {    var html = ';   $.each (data,function (i,item) {  html = ' <tr><td> ' +item[' name ']+ ' </td> ' +  ' <td > ' +item[' Sex ']+ ' </td> ' +  ' <td> ' +item.address+ ' </td> ' +  ' ≪td> ' +item[' home ']+ ' </td></tr> '; } ';  $ (' #title '). After (HTML); //after method: Inserts the content after each matching element.  }); }); });   //Note: Can be item.address, or can be item[' address '] //firefox report json file ' syntax error [', Single load data  //ie Chrome cannot load data   </script>  </HEAD>  <input type= "button" value= "Load data" ID = "LoadData"/>    <BODY>  <table id= "infotable" >  <tr id= "title" ><th> Name </th><th> sex </th><th> address </th><th> home </th></tr>  </table >  </BODY>  </HTML>    Info.json file     code as follows: [  {  "name": " Zhangsan ", " Sex ":" Man ", " Address ":" Hangzhou ", " Home ":" http://www.zhangsan.com " },  {   "name": "Lisi",  "Sex": "Wumen",  "Address": "Beijing",  "Home": "Http://www.lisi.coms"  }  ]    Application Scenarios:    regularly read specific records from the database to the static page to display, in order to reduce the database visitAsk the pressure to put a specific number of records out to store in JSON, page access links do not need to request the database in real time.     You can load the contents of JSON into HTML static as well.     does not show Chinese is really a coding problem, the default saved JSON is definitely a notepad, and then change the suffix named JSON, notepad default encoding is ANSI display Chinese naturally problematic,    solution: Open. json file File- Save to see the following coding format Bar select UTF-8 on it.     Here's another error-prone place.:  Request JSON file 405 error, clearly the path is correct but still error.   Workaround: Modify request:  for GET request

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.