Log in

View Full Version : [Ajax Beginner] ^^



sysout
09-23-2009, 02:41 AM
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</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.responseText;
}
}
XMLHttpRequestObject.send(null);
}
}
</script>
</head>
<body>
<h1>Fetching Data Using Ajax</h1>
<form>
<input type="button" value="Display Message" onclick="getData('data.txt', 'targetDiv')" />
</form>
<div id="targetDiv"><p>The Fetched Data will go here</p></div>
</body>
</html>


I can't trace the error :(
data.txt : Ajax

forum_amnesiac
09-23-2009, 06:18 AM
Is that all of your code, can you be a bit more specific about the error.

I've tried running the code as posted but apart from the button there is no input field in the DIV to test.

sysout
09-23-2009, 07:06 AM
yeah, it's work :(
I put it in .html..:D it must be .php

thanks palz