0

我有以下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]

4

3 回答 3

1

varxmlhttp,并传递""给 .send()。就是这样。

于 2010-05-27T22:35:52.710 回答
0
var xmlhttp = new XMLHttpRequest();

我猜这里

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

也许在 Prism 中您确实处于与浏览器页面中不同的环境中这一事实会有所不同。

于 2010-05-27T22:08:56.180 回答
0

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

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

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

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

于 2010-05-27T22:13:14.383 回答