码迷,mamicode.com
首页 > Web开发 > 详细

ajax

时间:2017-11-27 12:42:15      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:请求   jsonp   fun   成功   cli   .ajax   操作   XML   type   

jq的ajax方法

$.ajax({
   url:"/test.php",
   type:"post",
   async:true,            //是否异步
   data:{name:"张三",age:23},       //传入数据
   timeout:5000,         // 超时时间(毫秒)
   dataType:"jsonp",     //返回数据格式
   success:function(data,textStatus,jqXHR){
         console.log(data);  
   },         //成功执行函数
   error:function(){
         console.log("错误");
   },        // 请求失败时调用此函数
   beforesend:function(){
        
   },    //向服务器发送请求前执行一些动作
    complete:function(){
        
    }    //请求完成后回调函数 (请求成功或失败之后均调用)
    
})          

 

原生的ajax方法

btn.onclick=function(){
    var xhrObj=new XMLHttpRequest();  //创建一个ajax对象
    xhrObj.open("POST","test.php",true);   
    xhrObj.send();    //发送
    xhrObj.onreadystatechange=function(){
        if(xhrObj.readyState==4 && xhrObj.status==200){
               console.log(xhrObj.responText);       
         }
    }   //执行操作
      
}        

 

ajax

标签:请求   jsonp   fun   成功   cli   .ajax   操作   XML   type   

原文地址:http://www.cnblogs.com/xlj-code/p/7903419.html

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