码迷,mamicode.com
首页 > 其他好文 > 详细

笔记-Ajax[2]-代码的实现。

时间:2014-06-29 13:17:13      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   width   数据   2014   

<script>

  var xhr;

  //创建一个ajax的对象

  try{

    xhr=new XMLHttpRequest();

  }catch(e){

    xhr=new ActiveXObject("Microsoft.XMLHTTP");

  }

  //建立请求

  xhr.open(‘post‘,‘/ajax/content.php‘,true);

  //发送请求  

  xhr.send(‘username=Ajax‘);

  //响应

  xhr.onreadystatechange=function(){

      if ( xhr.readyState == 4 ) {//status是服务器返回的http状态码,200代码成功.
        if ( xhr.status == 200 ) {
          alert( xhr.responseText ); //responseText是xhr的一个属性,服务器返回的内容数据就放在responseText中,数据内容都是字符串类型。
        } else {
        alert(‘出错了,Err:‘ + xhr.status);
      }

  }

 

</script>

bubuko.com,布布扣

笔记-Ajax[2]-代码的实现。,布布扣,bubuko.com

笔记-Ajax[2]-代码的实现。

标签:style   blog   http   width   数据   2014   

原文地址:http://www.cnblogs.com/hellome/p/3770023.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!