Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Ajax
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 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 July 21st, 2015, 09:28 PM
Authorized User
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:
<!DOCTYPE html>
<script language = "javascript">

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

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


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

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