AJAX funciona bien en Firefox, pero un mal funcionamiento en Mozilla Prism 0.9
-
05-10-2019 - |
Pregunta
Tengo la siguiente función 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')">
Todo esto funciona bien en Firefox pero cuando se utiliza prisma 0.9, funciona mal y me sale el siguiente error en la consola de errores:
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]
Solución
var
la xmlhttp, y pasar ""
a .send (). Eso es todo.
Otros consejos
var xmlhttp = new XMLHttpRequest();
I'm guessing here.
As to the other (more serious) issue, here's a page I found: https://developer.mozilla.org/en/nsIXMLHttpRequest
Perhaps the fact that inside Prism you're really in a different environment than you are inside a browser page makes a difference.
As @Pointy says, declare the xmlhttp
variable.
Also for line 25, the corresponding line from jQuery (as an example) is:
xhr.send( type === "POST" || type === "PUT" || type === "DELETE" ? s.data : null );
If you're only ever GETting, xmlhttp.send(null)
would be fine.