JSON file data
[ {"name": "Haha •", "email": "E-mail", "gender": "Male", "hobby": ["Internet", "Play Ball"]}, {"name": "Hehe •", " Email ":" E-mail "," gender ":" Male "," hobby ": [" online shopping "," Play Ball "]}]
Read the JSON file and display it in the element
<!DOCTYPE HTML><HTML><HeadLang= "en"> <MetaCharSet= "UTF-8"> <title></title> <Scriptsrc=".. /lib/jquery/jquery.min.js "></Script></Head><Body> <DivID= "Reslut"></Div><Script>$ (document). Ready (function() {$.ajax ({/*Request Method*/Type:"GET", /*JSON file location*/URL:"User.js", /*return Data format as JSON*/DataType:"JSON", /*the method to execute after the request is completed successfully*/Success:function(data) {/*use the $.each method to traverse the data returned*/$.each (data,function(index,obj) {varcontent=Obj.name+","+Obj.email+","+Obj.gender+","+obj.hobby[0]+","+obj.hobby[1]+"<br/>"; /*insert into an element with a class name of Reslut*/ $("#reslut"). append (content); }); } }) });</Script></Body></HTML>
Jqery Ajax Reading JSON file