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