吾欲乘风

腰缠十万贯,骑鹤下扬州。

ajax应用

<script language="javascript" type="text/javascript">
//建立XMLHttpRequest对象(跨浏览器)
function creatXMLHttpRequest() {
 var req = false;
 // branch for IE/Windows ActiveX version
 if (window.ActiveXObject) {
  try {
   req = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
   try {
    req = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (e2) {
    req = false;
   }
  }
    }
  // branch for native XMLHttpRequest object
 else if (window.XMLHttpRequest) {
  try {
   req = new XMLHttpRequest();
  } catch (e) {
   req = false;
  }
 }
//判断是否初始化成功,如错误给出提示
if (!req)
  alert("Error initializing XMLHttpRequest!");

return req;
}

</script>

<script language="javascript" type="text/javascript">
var request = creatXMLHttpRequest();

function getCustomerInfo() {
     var phone = document.getElementById("phone").value;
     var url = "/cgi-local/lookupCustomer?phone=" + escape(phone);
     //服务器端根据请求返回信息(可以是完整页面,也可以是一个数据)
     request.open("GET", url, true);
     request.onreadystatechange = updatePage;
     request.send(null);
   }

function updatePage() {
 if (request.readyState == 4) {
  if (request.status == 200) {
   document.getElementById("info").innerHTML = request.responseText;
  } else {
   alert("There was a problem retrieving the XML data:/n" +
    request.statusText);
  }
 }
}

</script>

阅读更多
个人分类: ajax
上一篇掌握 Ajax,第 1 部分: Ajax 简介
下一篇java规范
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭