原始异步请求:
var xhl;
if(XMLhttprequest){
xhl=new XMLhttprequest();
}
else{
xhl=new ActiveXObject("Micosoft.XMLHTTP....");
}
xhl.open("Get",路径,true);
xhl.send();
xhl.onreadyStatechange=function(date){
if(xhl.stats==200&&xhl.readstate=4){
if(date=="ok"){
alert('登录成功!');
}
else{
alert('登录失败');
}
}
}
原始封装异步方法:
$(function(){
myajax("get",路径,function(date){
if(date=="ok"){
alert('登录成功!');
}
else{
alert('登录失败');
}
});
})
function myajax(httprequest,url,callback){
var xhl;
if(XMLhttprequest){
xhl=new XMLhttprequest();
}
else{
xhl=new ActiveXObject("Micosoft.XMLHTTP....");
}
xhl.open("Get",url,true);
xhl.send();
xhl.onreadyStatechange=function(){
if(xhl.stats==200&&xhl.readstate=4){
calllback(xhl.responseText);
}
}
用jquery异步方法:
$.get("路径",["id":11,"name":22],function(date){
if(date=="ok"){
alert('登录成功!');
}
else{
alert('登录失败');
}
});
$.post("路径",["id":11,"name":22],function(date){
if(date=="ok"){
alert('登录成功!');
}
else{
alert('登录失败');
}
});
用ajax异步方法:
$.ajax({
url:"路径",
date:["id":11,"name":22],
type:"post",
success:function(date){
if(date=="ok"){
alert('登录成功!');
}
else{
alert('登录失败');
}
}
})