Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-28-2012, 10:47 AM   PM User | #1
my_mirror_image
New to the CF scene

 
Join Date: Jan 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
my_mirror_image is an unknown quantity at this point
Angry Ajax code always says readystate never from changes 1 & response text is null always

This is my html code
*************************************************
<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>

<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>

</body>
</html>
********************************************************
ajax_info.txt
*************************************************
Hi this is text file
my_mirror_image is offline   Reply With Quote
Old 01-29-2012, 08:24 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Are you running this code on an actual webserver or locally (file based)?
devnull69 is offline   Reply With Quote
Old 01-29-2012, 09:06 AM   PM User | #3
my_mirror_image
New to the CF scene

 
Join Date: Jan 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
my_mirror_image is an unknown quantity at this point
Hi devnull69,I am running this locally file based Using Eclipse PDT.
I tried it even using response from php..it didn't work out.....
And my workspace is htdocs folder whose location is C:\xampp\htdocs
I start apache server using xampp and run the above code from eclipse..
I have spent a day searching about the problem..it would be really gr8full if you do some favor....

when i run admin.html a browser tab with url=http://127.0.0.1:8020/Admin/admin.html opens up.
when i click the button nothing loads...i used firebug to detect the issue..
I found that ready state never changes from 1...
Responsetext is always empty string...
Please feel free to ask any further info...
Thank you for your kind reply...
my_mirror_image is offline   Reply With Quote
Old 01-29-2012, 11:30 AM   PM User | #4
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
I can't say anything about the constellation eclipse/xampp but judging from your quote
Quote:
I am running this locally file based
I'd have to say: Ajax requests are only possible if the two pages (the one initiating and the one receiving the request) are running on the same WEBSERVER. Just opening up a local .html file and running its javascript connecting to another local file will NOT work.

EDIT: Another hint I had to learn some time ago: Please specify the onreadystatechange assignment AFTER the .open() line otherwise it won't work correctly on some browsers/configurations.
devnull69 is offline   Reply With Quote
Old 01-29-2012, 03:40 PM   PM User | #5
my_mirror_image
New to the CF scene

 
Join Date: Jan 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
my_mirror_image is an unknown quantity at this point
I am pleased by your response!Thank you!will try running on the same WEBSERVER....
my_mirror_image is offline   Reply With Quote
Reply

Bookmarks

Tags
ajax, null, readystate

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:20 PM.


Advertisement
Log in to turn off these ads.