开发者

AJAX works fine in firefox, but malfunctions in Mozilla Prism 0.9

I have the following ajax function:

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: unc开发者_开发知识库aught 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 the xmlhttp, and pass "" to .send(). Thats it.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜