Ajax在Firefox中工作正常,但Mozilla Prism的故障0.9
-
05-10-2019 - |
题
我有以下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]
解决方案
var
XMLHTTP,通过 ""
发送()。就是这样。
其他提示
var xmlhttp = new XMLHttpRequest();
我在这里猜。
至于另一个(更严重)的问题,这是我发现的页面: https://developer.mozilla.org/en/nsixmlhttprequest
也许内部的棱镜您确实处于与浏览器页面内部不同的环境中的事实有所不同。
正如@Pointy所说,声明 xmlhttp
多变的。
同样对于第25行,JQuery的相应行(例如)是:
xhr.send( type === "POST" || type === "PUT" || type === "DELETE" ? s.data : null );
如果你只得到 xmlhttp.send(null)
会没事的。
不隶属于 StackOverflow