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

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 11-04-2011, 09:58 AM   PM User | #1
Mr.
Regular Coder

 
Join Date: Feb 2011
Posts: 112
Thanks: 8
Thanked 4 Times in 4 Posts
Mr. is an unknown quantity at this point
my first AJAX attempt will not work... why...

Can you please tell me if you spot a problem.. when I run the page nothing appears.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Simple Ajax</title>
<script>
window.onload = makeRequest;
var xhr = false;

function makeRequest(){
	if(window.XMLHttpRequest){
		xhr = new XMLHttpRequest();

	}
	else {
		if (window.ActiveXObject) {
		try {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e) { }
		}
	}
}
	if (xhr) {

		xhr.onreadystatechange = showState;
		xhr.open("GET", "states.xml", true);
		xhr.send(null);
	}
	else {
		document.getElementById("updateArea").innerHTML = "Sorry, but I couldn't create a request";	
	}
	
function showState() {
	var currMsg = document.getElementById("updateArea").innerHTML;
	document.getElementById("updateArea").innerHTML = currMsg + "<p>The current state is " + xhr.readyState + " and the status is " + xhr.status + "</p>";	
}


</script>
</head>

<body>
<div id="updateArea">&nbsp;</div>
</body>
</html>
You can find the XML file at... http://www.testwebdesign.com/states.xml
Mr. is offline   Reply With Quote
Old 11-04-2011, 10:11 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Nothing obvious with your code ... you'll either have to debug (Firebug is your friend on Firefox) to find out what's going on or give us a (test) URL where we can observe the behaviour.
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
Mr. (11-04-2011)
Old 11-04-2011, 10:14 AM   PM User | #3
Mr.
Regular Coder

 
Join Date: Feb 2011
Posts: 112
Thanks: 8
Thanked 4 Times in 4 Posts
Mr. is an unknown quantity at this point
This is the test live...

http://www.testwebdesign.com/SimpleAJAX.html
Mr. is offline   Reply With Quote
Old 11-04-2011, 10:19 AM   PM User | #4
Mr.
Regular Coder

 
Join Date: Feb 2011
Posts: 112
Thanks: 8
Thanked 4 Times in 4 Posts
Mr. is an unknown quantity at this point
I got it... it was a misplaced curly bracket. Thanks for the help anyway!
Mr. 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 10:50 PM.


Advertisement
Log in to turn off these ads.