Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ajax not working

 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<html>
<head>
<title> This is Using Ajax</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 tag=document.getElementById(divID);
XMLHttpRequestObject.open("GET",datasource);

XMLHttpRequestObject.onreadystatechange=function(){
if(XMLHttpRequestObject.readyState==4 && XMLHttpRequestObject.status==200)
{
tag.innerHTML=XMLHttpRequestObject.responseText;
}
}
XMLHttpRequestObject.send(null);
}
}
</script>
</head>

<body>

<form>
<input type="button" value="Click to see message"
onclick="getdata('mata.txt','targetDiv')">
</form>

<div id="targetDiv">
<p> Your Message Will Appear Here</p>
</div>
</body>
</html>

File mata.txt have just a line
But when i click the button it does not retrieve data from the file

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, please repost the code using proper indentation and UseCodeTags.

Second, use the browser's debugger to step through the code and see what's going wrong. The network panel will tell you whether the request even fires off or not.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic