Data processing for Ajax

Source: Internet
Author: User

<! 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

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.