Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-19-2009, 05:04 PM   PM User | #1
ilbo
New Coder

 
Join Date: Jul 2009
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
ilbo is an unknown quantity at this point
Never reach readystate 4

Hello, for some reason I never reach readystate "4" for when I make a call to the search function below. It doesn't seem to matter if I make the call one or more times, but when I change "true" to "false" in the httpObject.open method, I reach readysate 4. The "method" variable specifies the file name (e.g. "helloworld.php"). Any thoughts?

Quote:
function search(method){
var httpObject = getHTTPObject();
if (httpObject != null)
{
httpObject.open("GET", method, true);
httpObject.send(null);
httpObject.onreadystatechange = setOutput(httpObject);
}
}

function getHTTPObject(){
if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest) return new XMLHttpRequest();
else
{
alert("Your browser does not support AJAX.");
return null;
}
}

function setOutput(httpObject){
if(httpObject.readyState == 4)
{
alert("Hello world!");
}
}

Last edited by ilbo; 07-19-2009 at 05:15 PM..
ilbo is offline   Reply With Quote
Old 07-19-2009, 05:44 PM   PM User | #2
ckeyrouz
Senior Coder

 
ckeyrouz's Avatar
 
Join Date: Jun 2009
Location: Montreal, Canada
Posts: 1,044
Thanks: 5
Thanked 179 Times in 179 Posts
ckeyrouz is on a distinguished road
Go to this URL:
http://www.devguru.com/Technologies/...arseError.html


you might need to alert(httpObject.parseError.reason)

there are many xml debugging properties that you can find in this page.
ckeyrouz is offline   Reply With Quote
Old 07-19-2009, 10:15 PM   PM User | #3
randomuser773
Banned

 
Join Date: Nov 2008
Location: not found
Posts: 284
Thanks: 0
Thanked 53 Times in 51 Posts
randomuser773 can only hope to improve
Quote:
Originally Posted by ilbo View Post
Hello, for some reason I never reach readystate "4" for when I make a call to the search function below. It doesn't seem to matter if I make the call one or more times, but when I change "true" to "false" in the httpObject.open method, I reach readysate 4. The "method" variable specifies the file name (e.g. "helloworld.php"). Any thoughts?
Perhaps:

httpObject.onreadystatechange = function(){ setOutput( this ); };
randomuser773 is offline   Reply With Quote
Old 07-19-2009, 11:13 PM   PM User | #4
ilbo
New Coder

 
Join Date: Jul 2009
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
ilbo is an unknown quantity at this point
I'm not outputting any XML though. It's just a PHP script that performs several databasing operations.

Last edited by ilbo; 07-19-2009 at 11:16 PM..
ilbo is offline   Reply With Quote
Old 07-19-2009, 11:14 PM   PM User | #5
ilbo
New Coder

 
Join Date: Jul 2009
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
ilbo is an unknown quantity at this point
Also, I'm positive that the setOutput function is being called. I just never get the "4" readystate value.
ilbo is offline   Reply With Quote
Old 07-19-2009, 11:55 PM   PM User | #6
randomuser773
Banned

 
Join Date: Nov 2008
Location: not found
Posts: 284
Thanks: 0
Thanked 53 Times in 51 Posts
randomuser773 can only hope to improve
Quote:
Originally Posted by ilbo View Post
Also, I'm positive that the setOutput function is being called. I just never get the "4" readystate value.
Another thing I just noticed is that you must always install the readystatechange handler before calling send.
randomuser773 is offline   Reply With Quote
Old 07-20-2009, 12:01 AM   PM User | #7
ilbo
New Coder

 
Join Date: Jul 2009
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
ilbo is an unknown quantity at this point
I moved the readystatechange handler up, but that doesn't seem to do it.

This is weird because I get the readystate 4 value when I use "false" in the httpObject.open method.

Last edited by ilbo; 07-20-2009 at 12:05 AM..
ilbo is offline   Reply With Quote
Old 07-20-2009, 12:15 AM   PM User | #8
randomuser773
Banned

 
Join Date: Nov 2008
Location: not found
Posts: 284
Thanks: 0
Thanked 53 Times in 51 Posts
randomuser773 can only hope to improve
Quote:
Originally Posted by ilbo View Post
I moved the readystatechange handler up, but that doesn't seem to do it.

This is weird because I get the readystate 4 value when I use "false" in the httpObject.open method.
Another thing I just noticed is that the request object isn't global so it gets hosed when the creating function ends. That's why it survives for a synchronous request.
Looks like you made all the common mistakes in one attempt.
randomuser773 is offline   Reply With Quote
Old 07-20-2009, 01:40 AM   PM User | #9
ilbo
New Coder

 
Join Date: Jul 2009
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
ilbo is an unknown quantity at this point
I made it global. No go.
ilbo is offline   Reply With Quote
Old 07-20-2009, 02:03 AM   PM User | #10
randomuser773
Banned

 
Join Date: Nov 2008
Location: not found
Posts: 284
Thanks: 0
Thanked 53 Times in 51 Posts
randomuser773 can only hope to improve
Quote:
Originally Posted by ilbo View Post
I made it global. No go.
Perhaps you could show the updated code, or preferably a test URL?
randomuser773 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 09:25 AM.


Advertisement
Log in to turn off these ads.