ajax调用java后台方法是什么

2016-12-01

ajax是一种基于 JavaScript和HTTP请求(HTTP requests),广泛应用在浏览器的网页开发技术。那么,ajax调用java后台方法是什么?

var http_request=false;

function sendRequest(method,url,content,processResponse)

{

http_request=false;

if(window.XMLHttpRequest) //mozilla

{

http_request=new XMLHttpRequest();

}else if(window.ActiveXObject) //IE

{

try

{

http_request=new ActiveXObject("Msxml2.XMLHTTP");

}catch(e)

{

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

}

}

if(!http_request)

{

alert("异步通信对象创建失败!");

return;

}

if(method.toLowerCase()=="get")

{

http_request.open(method,url,true);

http_request.onreadystatechange=processResponse;

http_request.send(content);

return;

}

if(method.toLowerCase()=="post")

{

http_request.open(method,url,true);

http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

http_request.onreadystatechange=processResponse;

http_request.send(content);

return;

}

}

function getResult()

{

if(window.http_request.readyState==4)

{

if(window.http_request.status==200)

{

//这是返回的结果

var rText=window.http_request.responseText;

//处理结果

if(rText=="true")

{

alert("用户名称已经存在");

}else{

alert("用户名称可以使用");

}

}

}

}

//调用

sendRequest("POST","user.do","userName="+name,getResult);

更多相关阅读

最新发布的文章