欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
Ajavx中使用回调函数返回属性
回调函数是一种作为参数被传递到另一个函数的函数。
 
如果您的网站中有多个 AJAX 任务,那么您应该创建一个执行 XMLHttpRequest 对象的函数,以及一个供每个 AJAX 任务的回调函数。
 
该函数应当包含 URL 以及当响应就绪时调用的函数。
 
实例
loadDoc("url-1", myFunction1);
 
loadDoc("url-2", myFunction2);
 
function loadDoc(url, cFunction) {
  var xhttp;
  xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      cFunction(this);
    }
  };
  xhttp.open("GET", url, true);
  xhttp.send();
}
 
function myFunction1(xhttp) {
  // action goes here
 } 
function myFunction2(xhttp) {
  // action goes here
 } 
 
服务器响应属性
属性 描述
responseText 获取字符串形式的响应数据
responseXML 获取 XML 数据形式的响应数据
服务器响应方法
方法 描述
getResponseHeader() 从服务器返回特定的头部信息
getAllResponseHeaders() 从服务器返回所有头部信息

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h64528.shtml