File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Ajax not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Ajax not working " Watch "Ajax not working " New topic
Author

Ajax not working

Mahtab Alam
Ranch Hand

Joined: Mar 28, 2012
Posts: 319

<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



http://www.mahtabalam.net , Oracle Java Programmer , Oracle SQL Expert , Oracle Java Web Component Developer
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ajax not working