views:

131

answers:

3

I have the following ajax fucntion:

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')">

This whole thing works fine in firefox but when i use prism 0.9, it malfunctions and i get the following error in the errors console:


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]

A: 
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.

Pointy
Thanks i tried it and it still throws the same errors.
Babiker
A: 

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.

wombleton
Thanks guys i really appreciate your help. I tried var xmlhttp and null as a param of .send() and still no use. This might sound a bit ridiculous but i think prism should still be able to use GET even without an address bar right?
Babiker
Wait, you're getting *exactly* the same errors after changing those two lines? And the new code is getting run?
wombleton
+1  A: 

var the xmlhttp, and pass "" to .send(). Thats it.

Sean Kinsey