不卡AV在线|网页在线观看无码高清|亚洲国产亚洲国产|国产伦精品一区二区三区免费视频

學(xué)習(xí)啦 > 知識(shí)大全 > 方法百科 > 產(chǎn)品使用方法 > ajax調(diào)用java后臺(tái)方法是什么

ajax調(diào)用java后臺(tái)方法是什么

時(shí)間: 歐東艷656 分享

ajax調(diào)用java后臺(tái)方法是什么

  ajax是一種基于 JavaScript和HTTP請(qǐng)求(HTTP requests),廣泛應(yīng)用在瀏覽器的網(wǎng)頁開發(fā)技術(shù)。那么,ajax調(diào)用java后臺(tái)方法是什么?

  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("異步通信對(duì)象創(chuàng)建失敗!");

  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)

  {

  //這是返回的結(jié)果

  var rText=window.http_request.responseText;

  //處理結(jié)果

  if(rText=="true")

  {

  alert("用戶名稱已經(jīng)存在");

  }else{

  alert("用戶名稱可以使用");

  }

  }

  }

  }

  //調(diào)用

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

 

308684