首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

Head First Ajax 的一个疑问?该怎么处理

2012-03-22 
Head First Ajax 的一个疑问?JScript codewindow.onload initPagefunction initPage() {// find the th

Head First Ajax 的一个疑问?

JScript code
window.onload = initPage;function initPage() {  // find the thumbnails on the page  thumbs = document.getElementById("thumbnailPane").getElementsByTagName("img");  // set the handler for each image  for (var i = 0; i < thumbs.length; i++) {    image = thumbs[i];        // create the onclick function    image.onclick = function() {      // find the image name      detailURL = 'images/' + this.title + '-detail.jpg';      document.getElementById("itemDetail").src = detailURL;      getDetails(this.title);    }  }}function createRequest() {  try {    request = new XMLHttpRequest();  } catch (tryMS) {    try {      request = new ActiveXObject("Msxml2.XMLHTTP");    } catch (otherMS) {      try {        request = new ActiveXObject("Microsoft.XMLHTTP");      } catch (failed) {        request = null;      }    }  }  return request;}function getDetails(itemName) {  request = createRequest();  if (request == null) {    alert("Unable to create request");    return;  }  var url= "getDetails.php?ImageID=" + escape(itemName);  request.open("GET", url, true);  request.onreadystatechange = displayDetails;  request.send(null);}function displayDetails() {  if (request.readyState == 4) {    if (request.status == 200) {      detailDiv = document.getElementById("description");      detailDiv.innerHTML = request.responseText;    }  }}

displayDetails函数中的request对象没有定义,请问这个对象是什么对象,是浏览器内置的吗

[解决办法]
request在createRequest里定义了:request = new XMLHttpRequest();。而浏览器都内置了XMLHttpRequest对象(叫对象不合适吧?反正JS也没有类的概念)
[解决办法]
全局的,ajax要运行就是靠这个对象

热点排行