jquery AJAX Office JSON data Entry Implementation Tutorial

Source: Internet
Author: User
Tags eval xmlns

Preson.js File Contents

The code is as follows Copy Code

[
{
' Name ': ' Xiangwen '
},
{
' Name ': ' Mengjie '
}
]

XMLHttpRequest

-json-ajax:[support IE7 above]

The code is as follows Copy Code

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>XHR</title>
<style type= "Text/css" >
. de{width:450px; height:450px border:4px solid #ccc;}
. ok{width:450px; font-size:40px border-bottom:4px solid #ccc; display:block; text-decoration:none;}
</style>
<script type= "Text/javascript" >
function Json (URL) {
var ok = document.getElementById ("OK");
var json = document.getElementById ("JSON");
var xhr = new XMLHttpRequest ();
Xhr.onreadystatechange = function () {
if (xhr.readystate = = 4) {
if ((Xhr.status >= && xhr.status <) | | xhr.status = = 304) {
var cons = eval ("+ Xhr.responsetext +"));
Ok.onclick = function () {
json.innerhtml = "<li>" +cons[0].name+ "</li>";
}
}
}
}
Xhr.open ("Get", url, false);
Xhr.send (NULL);
}
Window.onload = function () {
Json ("Preson.js");
}
</script>
<body>
<div class= "de" >
<a href= "#" class= "OK" id= "OK" title= "JSON-XHR" >Json-XHR</a>
<div class= "JSON" id= "JSON" ></div>
</div>
</body>

Jquery-json-ajax:

The code is as follows Copy Code

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>untitled page</title>
<style type= "Text/css" >
. de{width:450px; height:450px border:4px solid #ccc;}
. ok{width:450px; font-size:40px border-bottom:4px solid #ccc; display:block; text-decoration:none;}
</style>
<script type= "Text/javascript" src= "Jquery-1.6.4.min.js" ></script>
<script type= "Text/javascript" >
function Jsonurl (URL) {
var $ok = $ ("#ok");
var $json = $ ("#json");
$ok. Click (function () {
$.ajax ({
Type: "Get",
Url:url,
Beforesend:function (XMLHttpRequest) {

},
Success:function (data, textstatus) {
var Preson = eval ("+ Data +"));
for (var i = 0; i < $json. length; i++) {
var li = "<li>" + preson[i].name+ "</li>";
$json. Append (LI);
}
},
Error:function () {
Alert ("Error");
}
});
});
}
$ (function () {
Jsonurl ("Preson.js");
});
</script>
<body>
<div class= "de" >
<a href= "#" class= "OK" id= "OK" title= "" >JSON-DATA</a>
<div id= "JSON" class= "JSON" ></div>
</div>
</body>

Okay, the above AJAX processing program only tested IE7 or above browser, the same I think in Ff,google browser should be normal use, as for IE6 no test, if there are questions you can comment on the message.

Related Article

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.