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);
}
}