Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Cant get an anonymous function to run off .onreadystatechange
Old 05-20-2006, 08:03 PM Cant get an anonymous function to run off .onreadystatechange
Novice Talker

Posts: 9
Trades: 0
I am using firefox as my browser. When I run this page it will go out and get my xml but doesnt do anything else. If I put an alert inside my anonymous function it never gets ran. Neither does anything else in the function, including my showData function. Anyone know why this is happening? thanx in advance for the help!

var XMLHttpRequestObject = false;
if(window.XMLHttpRequest){
XMLHttpRequestObject = new XMLHttpRequest();
}
else if(window.ActiveXObject){
XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}

function showData(xmldoc){
var docElement, usernameNode, usernameidNode, displayText;

docElement = xmldoc.documentElement;
usernameNode = docElement.firstChild;
usernameidNode = usernameNode.nextSibling;

displayText = usernameNode.firstChild.nodeValue + ' ' + usernameidNode.firstChild.nodeValue;

var target = document.getElementById('usernameoutput');
target.innerHTML = displayText;

}
function getUsernames(){

var searchvalue = document.getElementById("uname").value;
var datasource = "search_profiles_now.php?searchvalue=" + searchvalue;

if(XMLHttpRequestObject){
document.getElementById('loadimage').style.display = "inline";
XMLHttpRequestObject.open("GET", datasource);

XMLHttpRequestObject.onreadystatechange = function()
{
if(XMLHttpRequestObject.readyState == 4){
var xmldoc = XMLHttpRequestObject.responseXML;
showData(xmldoc);
}
}
document.getElementById('loadimage').style.display = "none";
XMLHttpRequestObject.send(null);
}
}

Last edited by twizler; 05-20-2006 at 08:21 PM..
twizler is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-20-2006, 08:51 PM Re: Cant get an anonymous function to run off .onreadystatechange
Novice Talker

Posts: 9
Trades: 0
I added true to my .readystatechange and this got me into my anonymous function.

XMLHttpRequestObject.open("GET", datasource, true);


However now its saying xmldoc had no properties. hmmmm anyone know whats stopping the response from being put into xmldoc? The error is coming from line 12 which is in my showData function:

function showData(xmldocument){
var docElement, usernameNode, usernameidNode, displayText;

docElement = xmldocument.documentElement;
usernameNode = docElement.firstChild;
usernameidNode = usernameNode.nextSibling;

displayText = usernameNode.firstChild.nodeValue + ' ' + usernameidNode.firstChild.nodeValue;

var target = document.getElementById('usernameoutput');
target.innerHTML = displayText;

}

Last edited by twizler; 05-20-2006 at 09:02 PM..
twizler is offline
Reply With Quote
View Public Profile
 
Old 05-21-2006, 12:12 AM Re: Cant get an anonymous function to run off .onreadystatechange
Novice Talker

Posts: 9
Trades: 0
No one has responded to my post and I have been trying to get this code running. My post maybe confusing so here is my full code as it stands. The error I am getting is xmldoc has no properties

My code:

var XMLHttpRequestObject = false;
if(window.XMLHttpRequest){
XMLHttpRequestObject = new XMLHttpRequest();
}
else if(window.ActiveXObject){
XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}

function showData(xmldoc){
var docElement, usernameNode, usernameidNode, displayText;

docElement = xmldoc.documentElement;
usernameNode = docElement.firstChild;
usernameidNode = usernameNode.nextSibling;

displayText = usernameNode.firstChild.nodeValue + ' ' + usernameidNode.firstChild.nodeValue;

var target = document.getElementById('usernameoutput');
target.innerHTML = displayText;

}
function getUsernames(){

var searchvalue = document.getElementById("uname").value;
var datasource = "search_profiles_now.php?searchvalue=" + searchvalue;

if(XMLHttpRequestObject){
document.getElementById('loadimage').style.display = "inline";
XMLHttpRequestObject.open("GET", datasource, true);

XMLHttpRequestObject.onreadystatechange = function()
{
if(XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200){
var xmldocument = XMLHttpRequestObject.responseXML;
showData(xmldocument);
document.getElementById('loadimage').style.display = "none";
}
}
XMLHttpRequestObject.send(null);
}
}

I am running firefox and have fire bug. My javascript is getting my xml data back to the browser but im still getting xmldoc has no properties. Any ideas?!
twizler is offline
Reply With Quote
View Public Profile
 
Old 05-21-2006, 12:12 PM Re: Cant get an anonymous function to run off .onreadystatechange
Novice Talker

Posts: 9
Trades: 0
Finally fixed my own issue. I was missing header("Content-type: text/xml"); in my xml document so javascript didnt know what it was looking at.
twizler is offline
Reply With Quote
View Public Profile
 
Old 05-21-2006, 03:16 PM Re: Cant get an anonymous function to run off .onreadystatechange
vangogh's Avatar
Post Impressionist

Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Glad you got it all worked out. Sorry no one was able to help. I think it was just a combination of AJAX being new to a lot of people and that weekends aren't as bus around here. Fortunately you were able to get the issue resolved on your own.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Reply     « Reply to Cant get an anonymous function to run off .onreadystatechange
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.18382 seconds with 12 queries