Ajax 应用程序适用于某些浏览器,而不适用于其他浏览器

标签 ajax internet-explorer-8

我的 ajax 应用程序在 Firefox 中运行良好,但在 IE8 中却无法运行。具体来说,ajax 功能不起作用。

这是我正在使用的代码:

function createXMLHttpRequest()
{
  if (window.XMLHttpRequest)
  {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    return new XMLHttpRequest();
  }

  if (window.ActiveXObject)
  {
    // code for IE6, IE5
    return new ActiveXObject("Microsoft.XMLHTTP");
  }

  return null;
}

这是错误:
Object doesn't support this property or method
ajax.js
Code:0
Line : 6
Char : 5

它在 Firefox 中完美运行。

我的代码有什么问题?

最佳答案

直接从jQuery:

return window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") :
                              new XMLHttpRequest();

关于Ajax 应用程序适用于某些浏览器,而不适用于其他浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1482177/

相关文章:

c# - HttpResponse 中的 Angular 6 空 header 数组

php - 将多个同名输入添加到mysql数据库

javascript - 未捕获的类型错误 : callback is not a function

html - Zurb Foundation 5 的 IE 8 页脚不会全宽

子域的 Django 登录 cookie 在 IE8 中下划线被破坏?

javascript - 更改表单字段时更新数据库而不刷新

php - ajax get方法与mysql数据库一起使用

javascript - 当我使用 equalHeights jQuery 插件时,IE8 返回 “object doesn' t support this property or method”

internet-explorer - 输入文本/文本区域大小

internet-explorer - IE8 线性渐变、边界半径和不透明度