Click to See Complete Forum and Search --> : [RESOLVED] xmlHttpRequest -> NS_ERROR_NOT_FOUND


Kudose
12-05-2006, 04:41 AM
Hello all. Trying to get into Ajax here ... ran into a little problem.

The following code is supposed to just post the data and return the responseText. For some reason it makes it to readyState 2, then dies. I tried to debug it by displaying each readyState it makes it to, and all I get to is 2.

I have used the request object successfully on another page.

Any help would be appreciated.

ERROR
Error: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://www.xxx.xxx/xxxx/xxx.php :: showResult :: line 42" data: no]
Source File: http://www.xxx.xxx/xxx/xxx.php
Line: 42

JS Code
function submitBuddy(){
createRequest();
var url = "ajax-addBuddy.php?time=" + new Date().getTime();
var buddyID = document.getElementsByName('selectBuddy');
buddyID = buddyID[0].options[buddyID[0].selectedIndex].value;
request.open("POST", url, true);
request.onreadystatechange = showResult;
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.send("buddyID=" + escape(buddyID));
}
function showResult(){
var buddyForm = document.getElementById('buddyForm');
buddyForm.style.display = 'none';
var addingBuddy = document.getElementById('addingBuddy');
addingBuddy.style.display = 'block';
if(request.readyState == 4){
if(request.status == 200){
addingBuddy.style.display = 'none';
var addBuddyLinkArea = document.getElementById('addBuddyLinkArea');
addBuddyLinkArea.style.display = 'none';
if(request.responseText !== 0){
addingBuddy.innerHTML = '<b>Added Buddy Homie!!!!</b>';
addingBuddy.style.display = 'block';
} else {
addingBuddy.innerHTML = '<b>Error adding buddy. I\'m sorry, I tried.</b>';
addingBuddy.style.display = 'block';
}
} else {
alert("Error: Status code " + request.status);
}
}

MarkR
12-05-2006, 05:21 AM
You do realise that you have to place a FULL URL in the XHR object's "open" method, right?

I normally write a Javascript function which unpacks the window.location.href to find the URL of the gateway page relative to that.

You should install an extension in firefox (maybe live http headers or firebug) so you can see exactly what's being requested. Failing that, try using a sniffing tool (e.g. Ethereal / Wireshark) to view the request at a low level.

Mark

Kudose
12-05-2006, 06:10 AM
Thanks for your suggestion.

It turns out that the problem was that my submit button was type "submit" as oppose to type "button".

Thanks though.