Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Ajax
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Ajax the combination of XHTML, CSS, DOM, XML, XSLT, XMLHttpRequest, and JavaScript
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Ajax section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 21st, 2015, 09:28 PM
Authorized User
Points: 132, Level: 2
Points: 132, Level: 2 Points: 132, Level: 2 Points: 132, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 25
Thanks: 3
Thanked 0 Times in 0 Posts
Question Simple Ajax code will not work.

I'm doing this very simple Ajax code but, for some reason I can't get it to work. Could someone show me what I am doing wrong?

The code is below:
Code:
<!DOCTYPE html>
<html>
<head>
<script language = "javascript">

var XMLHttpRequestObject = false;
	if(window.XMLHttpRequest)
	{
		XMLHttpRequestObject - new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHttp");
	}
function getData(dataSource, divID)
{

	
	
	if(XMLHttpRequestObject)
	{
	var obj = document.getElementById(divID)
		XMLHttpRequestObject.open("GET", dataSource);
		
		XMLHttpRequestObject.onreadystatechange = function()
		{
			if(XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
			{
				obj.innerHTML = XMLHttpRequestObject.responseText;
			}
			else
			{
				obj.innerHTML = <strong>Waitning for response...</strong>
			}
		}
		XMLHttpRequestObject.send(null);
	}
	
}
</script>
</head>
<body>
<div id="text">
<p>Response will appear here.</p>
</div>
<form>
	<input type = "button" value = "Submit" onclick="getData('HelloWorld.php','divID')">
</form>

</body>
</html>
Reply With Quote
Reply


Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ajax authentication service class doesn't work with ToolKitScriptManagerl ravi shiggavi BOOK: ASP.NET AJAX Programmer's Reference : with ASP.NET 2.0 or ASP.NET 3.5 ISBN: 978-0-470-10998-4 0 May 17th, 2010 01:36 AM
ch11 "Using XML and Ajax" example doesn't work nick_rasband@byu.net BOOK: Beginning Ruby on Rails 2 March 27th, 2007 06:13 PM
code clinic - Why wont example asp code work? jardbf Classic ASP Basics 3 April 27th, 2006 06:22 PM
Chapter 15 simple-mailer.php doesn't work Corey Wirun BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 June 18th, 2003 03:13 PM



All times are GMT -4. The time now is 08:12 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.