<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<script>
var hahastr= "{' name ': ' Haha ', ' age ': ' Address ': ' Wuhan '}"; /* Note Here is the string,, but inside is the JSON data */
/* Why eval here to add ("(" +data+ ")")?
Since JSON begins and ends in the form of {}, it is treated as a block of statements in Eval, so it must be coerced into an expression.
The parentheses are used to cause the Eval function to force the expression in parentheses to be converted to an object instead of being executed as a statement (statement) when it is processed.
Without enclosing parentheses, Eval recognizes the curly brace as the opening and closing tag of the JS block, and {} is considered to have executed an empty statement. */
var test=eval ("(" +hahastr+ ")");
alert (test.name);
</script>
<body>
</body>
<! DOCTYPE html>
<!--
[Email protected]
Date: 2017-11-27
Describe:
Use HTML format to make requests
Advantages: Simple and convenient, can directly connect with the innerHTML
-
<meta charset= "UTF-8" >
<title></title>
<script>
Window.onload=function ()
{
var anode=document.getelementsbytagname ("a");
for (Var i=0;i<anode.length;i++)
{
Anode[i].onclick=function ()
{
var request=new xmlhttprequest ();
var method= "GET";
var url=this.href;
Request.open (Method,url);
Request.send (NULL);
Request.onreadystatechange=function ()
{
if (request.readystate==4)/* Note the S capital here */
{
if (request.status==200)
{
document.getElementById ("Div1"). Innerhtml=request.responsetext;
}
}
}
return false;
}
}
}
</script>
<body>
<a href= "Libai.txt" > Li Bai </a>
<a href= "Huanghelou.txt" > Yellow Crane Tower </a>
<a href= "Changjiang.txt" > Changjiang </a>
<div id= "Div1" style= "width:800px;height:200px;border:1px solid red;" ></div>
</body>
Data processing for Ajax