【问题标题】:AJAX works fine in firefox, but malfunctions in Mozilla Prism 0.9AJAX 在 Firefox 中运行良好,但在 Mozilla Prism 0.9 中出现故障
【发布时间】:2010-05-27 22:03:12
【问题描述】:

我有以下ajax函数:

function ajax(value, url, urlVarname, displayContainers_id){    
    if(value == ''){
        document.getElementById(displayContainers_id).innerHTML='';
    }
    /* THIS IS LINE 12*/ xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange=function()
    {
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
            document.getElementById(displayContainers_id).innerHTML=xmlhttp.responseText;
        }

    }
    xmlhttp.open('GET',url + '?varName=' + urlVarname + '&value=' + value, true);
    /* THIS IS LINE 25 */ xmlhttp.send();
}

 onmousedown="ajax(document.getElementById('searchParamater').value, 'http://192.168.0.7/controllers/search_controller.php', document.getElementById('searchBy').value, 'ajaxBucket')">

这整个事情在 Firefox 中运行良好,但是当我使用 prism 0.9 时,它出现故障,并且我在错误控制台中收到以下错误:


Warning: assignment to undeclared variable xmlhttp Source File: http://192.168.0.7/javascript/main.js Line: 12

Error: uncaught exception: [Exception... "Not enough arguments [nsIXMLHttpRequest.send]" nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" location: "JS frame :: http://192.168.0.7/javascript/main.js :: ajax :: line 25" data: no]

【问题讨论】:

    标签: javascript ajax firefox mozilla-prism


    【解决方案1】:

    var xmlhttp,并将"" 传递给 .send()。就是这样。

    【讨论】:

      【解决方案2】:
      var xmlhttp = new XMLHttpRequest();
      

      我猜这里。

      关于另一个(更严重的)问题,这是我找到的一个页面:https://developer.mozilla.org/en/nsIXMLHttpRequest

      也许您在 Prism 中所处的环境与您在浏览器页面中所处的环境确实不同。

      【讨论】:

        【解决方案3】:

        正如@Pointy 所说,声明xmlhttp 变量。

        同样对于第 25 行,来自 jQuery 的对应行(例如)是:

        xhr.send( type === "POST" || type === "PUT" || type === "DELETE" ? s.data : null );
        

        如果你只是 GETting,xmlhttp.send(null) 会很好。

        【讨论】:

        • 谢谢大家,非常感谢您的帮助。我尝试了 var xmlhttp 和 null 作为 .send() 的参数,但仍然没有用。这可能听起来有点荒谬,但我认为即使没有地址栏,prism 仍然应该能够使用 GET 对吧?
        • 等一下,您在更改这两行后得到完全相同的错误?新代码正在运行?
        猜你喜欢
        • 2013-09-27
        • 2014-12-25
        • 1970-01-01
        • 1970-01-01
        • 2020-07-02
        • 2013-06-23
        • 2011-03-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多