Ajax Talk - Asynchronous javascript and xml discussion board
 FAQ   Search    Usergroups      Register   Profile   Check your messages   Log in 
Signup now to enjoy a range of free membership advantages !!
Ajax Talk - Moderators Wanted
ajax php help!!

 
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> PHP
View previous topic :: View next topic  
Author Message
creedo
New one
New one


Joined: 02 Dec 2006
Posts: 1

PostPosted: Sat Dec 02, 2006 6:26 am    Post subject: ajax php help!! Reply with quote

hello i am new to using ajax on my php and i need some help.
i make a code to retrieve data and show it in my html and be refresh every second..the problem is it only works in mozilla based browser...in IE it only shows the code but it not refreshes even after i refresh it manually..i dont know what is the problem..could anyone help me here is my code.

this is the full code: http://pastebin.com/837366 below is the script part and the span.. :

#
<script type="text/javascript">
#
var page = "show.php";
#
document.getElementById(target).innerHTML = 'sending...';
#
function ajax(url,target)
#
{
#
// native XMLHttpRequest object
#

#
if (window.XMLHttpRequest) {
#
req = new XMLHttpRequest();
#
req.onreadystatechange = function() {ajaxDone(target);};
#
req.open("GET", url, true);
#
req.send(null);
#
// IE/Windows ActiveX version
#
} else if (window.ActiveXObject) {
#
req = new ActiveXObject("Microsoft.XMLHTTP");
#
if (req) {
#
req.onreadystatechange = function() {ajaxDone(target);};
#
req.open("GET", url, true);
#
req.send();
#
}
#
}
#
setTimeout("ajax(page,'scriptoutput')", 1000);
#
}
#
function ajaxDone(target) {
#
// only if req is "loaded"
#
if (req.readyState == 4) {
#
// only if "OK"
#
if (req.status == 200 || req.status == 304) {
#
results = req.responseText;
#
document.getElementById(target).innerHTML = results;
#
} else {
#
document.getElementById(target).innerHTML="ajax error:\n" +
#
req.statusText;
#
}
#
}
#
}
#
</script>
#
<title>
#
refresh test
#
</title>
#
<style type="text/css">
#
<!--
#
.style3 {
#
font-size: 9px;
#
font-weight: bold;
#
font-family: Verdana, Arial, Helvetica, sans-serif;
#
}
#
-->
#
</style>
#
</head>
#
<body onload="ajax(page,'scriptoutput')"><br />
#
<table width="340" height="241" border=0 bordercolor="#FF0000">
#
<tr>
#
<td width="330" height="235" align="left">
#
<span id="scriptoutput"> </span>
#

#
</td>

please help me..thanks to all of you.
_________________
RECYCLE!!!!!
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
alex94040
New one
New one


Joined: 28 Jan 2007
Posts: 3

PostPosted: Tue Jan 30, 2007 9:19 am    Post subject: Reply with quote

It's really impossible to debug code like that. What I'd suggest you is instead of working directly against the XMLHttpRequest object, take us of a framework - I personally love XAJAX. It's extremely easy, doesn't hide things that you don't want hidden, but doesn't make you sink into the same sand that many people already died in (little browser incompatibilities in the XHR).
Back to top
View user's profile Send private message Visit poster's website
php_penguin
New one
New one


Joined: 25 Jun 2007
Posts: 4
Location: Wales, UK

PostPosted: Tue Jun 26, 2007 10:11 pm    Post subject: Reply with quote

The problem is likely in the differences in how FF and IE process the setTimeout method.

if, instead of:
Code:
setTimeout("ajax(page,'scriptoutput')", 1000);


you did this:
Code:
setTimeout(function(){ ajax(page,'scriptoutput') }, 1000);

you might find some more success.

It's all very well complaining about the readability of a post, but if you don't know the answer, don't post.
Back to top
View user's profile Send private message MSN Messenger
evan_carothers
Light Frequent Poster
Light Frequent Poster


Joined: 11 Oct 2007
Posts: 9
Location: River Falls, WI

PostPosted: Thu Oct 11, 2007 9:21 pm    Post subject: Reply with quote

You could try using a framework like Prototype that has an Ajax.PeriodicalUpdater function that does exactly what you're looking for and is cross-browser compatible. Another problem I see is that your onreadystatechange function isn't checking to see what the state returned from the xmlhttprequest objest is. You want the function ajaxDone to only execute when the state is 4 (done). So this function is going to possibly be called 3 times throughout the course of the request being processed. In addition, once the setTimeout function goes again, after 1 second, it's sending a new request, so once the server gets the new request i will send the state back to the client again and again, meaning that you're going to be hitting the onreadystatechange function MUCH more than you intend. The javascript won't wait for the previous request to complete to send the new one one the setTimeout function hits, and the xmlhttprequest objects overwrite each other.
Back to top
View user's profile Send private message Send e-mail
evan_carothers
Light Frequent Poster
Light Frequent Poster


Joined: 11 Oct 2007
Posts: 9
Location: River Falls, WI

PostPosted: Thu Oct 11, 2007 9:24 pm    Post subject: Reply with quote

Ok, color me dumb i didn't see that you were processing the status in the ajaxDone function. Still though, the xmlhttprequest objects will overlap when the setTimeout function is called, which could be giving you problems as well.
Back to top
View user's profile Send private message Send e-mail
vikas1234
Frequent Poster
Frequent Poster


Joined: 24 Aug 2008
Posts: 29

PostPosted: Sun Jul 26, 2009 5:26 am    Post subject: Reply with quote

I would suggest you to read the manual for FF and IE process on AJAX
_________________
Free Online Books|Free pdf Books |free AJAX Books
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> PHP All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
 Advertisements
 XML & Copyright Notice 
    


Powered by phpBB © 2001, 2005 phpBB Group

What is according to Wikipedia: Ajax Web2.0 XML E4X


Link to our site:

  


del.icio.us digg spurl wists simpy newsvine blinklist furl blogmarks yahoo! myweb smarking ma.gnolia segnalo reddit fark technorati cosmos


Normal Bookmark


Partner Button Links:
Codecrunch.com: Webmaster Tutorials    One Ajax


Partner Text Links:
quomon | web20log | ajaxmatters | tableless | 456bereastreet | music charts | gift ideas | competitions | free xbox 360 | link trade ?


Credits:
it consultancy & project management lead generation zoekmachine optimalisatie steal these buttons seo expert