标签:请求 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); } } //执行操作 }
标签:请求 jsonp fun 成功 cli .ajax 操作 XML type
原文地址:http://www.cnblogs.com/xlj-code/p/7903419.html