Several states in the Ajax of jquery

Source: Internet
Author: User
XML file
Myfile.xml
<?xml version= "1.0" encoding= "Utf-8"?>
<List>
&LT;CB cname= "Beijing" cid= "1" >
<cs cname= "Beijing" cid= "364" > Beijing </CS>
</CB>
&LT;CB cname= "Tianjin" cid= "2" >
<cs cname= "Tianjin" cid= "365" > Tianjin </CS>
</CB>
&LT;CB cname= "Shanghai" cid= "3" >
<cs cname= "Shanghai" cid= "364" > Shanghai </CS>
</CB>
&LT;CB cname= "Chongqing" cid= "4" >
<cs cname= "Chongqing" cid= "365" > Chongqing </CS>
</CB>
</List>
*********************************************************

Show Page xml.php
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8" >
<title>xml Application </title>
<script language= "javascript" src= "Jquery.js" ></script>
<script language= "JavaScript" >
$ (document). Ready (function () {
$ ("button"). Click (function () {
$.ajax ({
Type: "Post",
URL: "Myfile.xml",
DataType: "xml",
Error:function () {
Alert ("There is an error.) ");
},
Success:function (XML) {
$ (XML). Find ("CB"). each (function () {
var cs = $ (this). FIND ("CS"). text ();
Alert ($ (this). Find ("CS"). attr ("CNAME");
$ ("#show"). Append ("<font color=maroon>" + cs + "</font>});
}
});
});
$ ("#show"). Ajaxstart (function () {
$ (this). Append ("<font color=red>1, ready to start </font>");
});
$ ("#show"). Ajaxsend (function () {
$ (this). Append ("<font color=red>2, start sending </font>");
});
$ ("#show"). Ajaxsuccess (function () {
$ (this). Append ("<font color=red>3, Transmission success </font>");
});
$ ("#show"). Ajaxcomplete (function () {
$ (this). Append ("<font color=red>4, Transmission completed </font>");
});
$ ("#show"). Ajaxstop (function () {
$ (this). Append ("<font color=red>5, Transmission stop </font>");
});
$ ("#show"). Ajaxerror (function () {
$ (this). Append ("<font color=red> transmission Failure </font>");
});

});
</script>
<body>
<button onclick= "Startajax ();" > Start ajax</button>
<div id= "Show" ></div>
</body>
Note: Ajaxsend,ajaxstart are global events that can be displayed correctly outside of other events, otherwise you can only run Ajaxsuccess,ajaxcomplete,ajaxstop
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.