Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fetch data from local data file 2

Status
Not open for further replies.

Dashsa

Programmer
Aug 7, 2006
110
US
Hello,
I am new to AJAX and I got the dummy book and tried the first example but it is failing, I was hoping you would be able to help me.
Thanks
Code:
<html>
<head>
<title> Ajax Test</title>
<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.resposeText;
		}
		}
		XMLHttpRequestObject.send(null);
		}
		}

</script>
</head>
<body>
<h1>Fetching Data with Ajax</h1>
<form>
<input type="button" value="Display Message" onclick="getData('[URL unfurl="true"]http://localhost/AJAX/data.txt'),[/URL] 'targetDiv');" />
</form>
<div id="targetDiv">
<p>
The Fetched Data will go here.
</p>
</div>
</body>
</html>
I am not getting an error code for the script it is just not working...
Thanks again.
 
When I run your code I get a syntax error on this line:

Code:
getData('[URL unfurl="true"]http://localhost/AJAX/data.txt'),[/URL] 'targetDiv');

As you can see, you have a mismatched bracket.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
P.S. use Firefox with the Firebug plugin - it's great for showing all sorts of errors.

At very least, the Firefox error console should show this error as well.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Thanks Dan,
I also had a spelling error , I got the code to work.
I had a look at the firefox plugin and it looks good- thanks for the tip!
David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top