jquery的ajax中的几种状态

xml文件
myfile.xml
<?xml version="1.0" encoding="utf-8" ?>
<List>
  <CB cname="北京" cid="1">
    <CS cname="北京" cid="364">北京市</CS>    
  </CB>
  <CB cname="天津" cid="2">
    <CS cname="天津" cid="365">天津市</CS>
  </CB>
  <CB cname="上海" cid="3">
    <CS cname="上海" cid="364">上海市</CS>
  </CB>
  <CB cname="重庆" cid="4">
    <CS cname="重庆" cid="365">重庆市</CS>
  </CB>
</List>
*********************************************************

展示页面xml.php
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>xml运用</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("有错误!");
   },
   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><hr />");
    });
   }
  });
});
$("#show").ajaxStart(function(){
  $(this).append("<font color=red>1、准备开始</font>");
});
$("#show").ajaxSend(function(){
  $(this).append("<font color=red>2、开始发送</font>");
});
$("#show").ajaxSuccess(function(){
  $(this).append("<font color=red>3、传送成功</font>");
});
$("#show").ajaxComplete(function(){
  $(this).append("<font color=red>4、传送完成</font>");
});
$("#show").ajaxStop(function(){
  $(this).append("<font color=red>5、传送停止</font>");
});
$("#show").ajaxError(function(){
  $(this).append("<font color=red>传送失败</font>");
});

});
</script>
</head>
<body>
<button οnclick="startajax();">开始ajax</button>
<div id="show"></div>
</body>
</html>
//注意:ajaxSend,ajaxStart等都是全局事件,放到其他事件外才能正确显示,否则只能运行ajaxSuccess,ajaxComplete,ajaxStop
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值