This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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: 249

<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



Oracle Java Programmer , Oracle SQL Expert , Oracle Java Web Component Developer
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

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]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Ajax not working