XMLHttpRequest()在最新版本的Firefox中不起作用? [英] XMLHttpRequest() does not work in the latest versions of Firefox?

查看:288
本文介绍了XMLHttpRequest()在最新版本的Firefox中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的插件中,我总是使用新的XMLHttpRequest(),它完美的工作。
现在所有请求ajax停止工作。

当前新的XMLHttpRequest()导致以下错误:ReferenceError:XMLHttpRequest未定义

因此,我将代码更改为:

  try {
var XMLHttpRequest;
if(typeof(XMLHttpRequest)==undefined)
XMLHttpRequest = content.XMLHttpRequest;
}
catch(e){
alert(e);
}
var xmlhttp = new XMLHttpRequest();
...

有时候请求通常有效,但有时候不会。



代码alert(e);这是没有执行,那么没有错误那里。

我不明白为什么有时它有效,有时不。
之前我只用了 var xmlhttp = new XMLHttpRequest(); ,并且一直工作。

现在我该如何创建一个新的ajax请求?

解决方案

正如我在评论中所说的,当你在浏览器窗口的上下文中运行时覆盖到那个窗口),那么 XMLHttpRequest 一定是可用的。但是,如果一切都失败了,你仍然可以直接实例化对应于XMLHttpRequest的XPCOM组件:$ / $> $ / $> $ / $> $ / $> b
$ b

var xmlhttp = Components.classes [@ mozilla.org/xmlextras/xmlhttprequest; 1]
.createInstance(Components.interfaces.nsIXMLHttpRequest);
xmlhttp.open(...);


In my addons I always used new XMLHttpRequest () and it worked perfectly. Now all requests ajax stopped working.

Currently new XMLHttpRequest () is causing the following error: ReferenceError: XMLHttpRequest is not defined

So I changed my code to:

try {
    var XMLHttpRequest;
    if (typeof(XMLHttpRequest) == "undefined")
        XMLHttpRequest = content.XMLHttpRequest;
}
catch (e) {
    alert(e);
}
var xmlhttp = new XMLHttpRequest();
...

Sometimes the request usually works, but sometimes not.

The code "alert(e);" is never executed, then there is no error there.

I can not understand why sometimes it works and sometimes not. Previously I used only var xmlhttp = new XMLHttpRequest(); and always worked.

Now how do I create a new ajax request?

解决方案

As I said in a comment, when you are running in the context of a browser window (like code loaded by an overlay to that window) then XMLHttpRequest should definitely be available. I verified that just in case and it works for me.

But in case everything else fails you can still instantiate the XPCOM component corresponding to XMLHttpRequest directly:

var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
                        .createInstance(Components.interfaces.nsIXMLHttpRequest);
xmlhttp.open(...);

这篇关于XMLHttpRequest()在最新版本的Firefox中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆