Wrox Programmer Forums
|
BOOK: JavaScript 24-Hour Trainer
This is the forum to discuss the Wrox book JavaScript 24-Hour Trainer Jeremy McPeak; ISBN: 978-0-470-64783-7
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: JavaScript 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 21st, 2012, 09:33 PM
Registered User
 
Join Date: Jun 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Lesson 33 AJAX readyState stuck at 1.

Hey I've figured out the problem is my readyState is stuck at 1 and not changing to 4 at the makeGetRequest stage.

here's the code I copied from the book

function makeGetRequest(url,callback){

var xhr = createXHR();
xhr.open("GET",url);

console.log(xhr.readyState //Returns 1
xhr.onreadystatechange=function (){
if(xhr.readyState ===4){

if ((xhr.status >=200 & xhr.status < 300) || xhr.status===304){

callback(xhr.responseText);
}else{
alert('something went wrong');
}//end else
}//end if

};//end function

a fix i've found is replacing xhr.onreadystatechange with xhr.onload any input would be appreciated thanks!
 
Old June 24th, 2012, 11:09 AM
jmcpeak's Avatar
Wrox Author
 
Join Date: Nov 2005
Posts: 87
Thanks: 0
Thanked 18 Times in 17 Posts
Default

Howdy, Bofonic.

How are you running this page? Are you double-clicking the icon? Pages using Ajax have to be served from a web server. So if you haven't already, setup a web server on your computer (if you're using Windows, WebMatrix is a nice solution), move the files to your web server's directory, and request the page through the browser.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Page 33 Misconception Patrick Cambria BOOK: Professional Visual Basic 2008 ISBN: 978-0-470-19136-1 0 December 16th, 2008 05:08 AM
Why is readyState always 1? sqad Ajax 5 April 29th, 2008 07:35 PM
Always getting readyState = 1 CraigMuckleston PHP How-To 0 June 15th, 2007 10:55 AM
readyState won't move from 1 to 2! lmireskandari Javascript 0 February 28th, 2007 11:50 AM
readyState not ready -- closed see google groups scottradny BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 March 30th, 2006 11:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.