尝试创建xmlhttprequest对象但失败

时间:2017-08-07 05:43:37

标签: javascript php

我正在尝试创建xml http请求对象,我无法找到我出错的地方,当我尝试提醒它打印错误的对象时



var xmlHttpObject = createXmlHttpRequestObject();
alert(xmlHttpObject); // return object is false is my problem 

function createXmlHttpRequestObject() {
  var xmlHttpObject;
  //mozilla browser
  if (window.ActiveXobject) {
    try {
      xmlHttpObject = new ActiveXobject("Microsoft.XMLHTTP");
      alert(xmlHttpObject);
    } catch (e) {
      xmlHttpObject = false;
    }
  } else {
    try {
      xmlHttpObject = XMLHttpRequest();
      alert('test'); //it is not coming in to the block itself
    } catch (e) {
      xmlHttpObject = false;
    }
  }

  if (xmlHttpObject) {
    alert("object created");
  } else {
    alert("object not created");
    return xmlHttpObject;
  }
}




2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

为了完整起见 - 这是考虑到

的脚本的更正版本

window.ActiveXObject difference in IE11

<img src="@Url.Content("~/photos/image.jpg")">