Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
AJAX cross-browser problems
Old 12-17-2007, 07:48 PM AJAX cross-browser problems
Skilled Talker

Posts: 64
Trades: 0
After looking into w3schools tutorial of AJAX I discovered that the below script works fine in Firefox with the time updating on keyup but in IE, it'll update once and thats it.

PHP Code:
<html>
<
body>

<
script type="text/javascript">
function 
ajaxFunction()
{
var 
xmlHttp;
try
  {
  
xmlHttp=new XMLHttpRequest();  // Firefox, Opera 8.0+, Safari
  
}
catch (
e)
  {
  try
    {
    
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");  // Internet Explorer
    
}
  catch (
e)
    {
    try
      {
      
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (
e)
      {
      
alert("Your browser does not support AJAX!");
      return 
false;
      }
    }
  }
   
  
xmlHttp.onreadystatechange=function()
    {
    if(
xmlHttp.readyState==4)
      {
      
document.myForm.time.value=xmlHttp.responseText;
      }
    }
    
      
xmlHttp.open("GET","time.php",true);
      
xmlHttp.send(null);

  }
</script>

<form name="myForm">
Name: <input type="text" onkeyup="ajaxFunction();" name="username" />
Time: <input type="text" name="time" />
</form>

</body>
</html> 
Looking on other websites that use AJAX such as Youtube and Google Labs the scripts they use to achieve cross-browser functionality are veeeerry long and way beyond my current meagre understanding of Javascript.

What methods do you use to get AJAX to work cross-browser and if at all, how could this script be edited to achieve that?


Edit: Oh, and using 'POST' doesn't help. Before you say

Edit2: Editing my headers not to allow caching didn't do anything

Edit3: Nor did using this bit of code instead:
var url = "time.php?ms=" + new Date().getTime();
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

Last edited by Petsmacker; 12-17-2007 at 08:35 PM..
Petsmacker is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-18-2007, 06:31 AM Re: AJAX cross-browser problems
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
http://www.webmaster-talk.com/javasc...r-message.html
post#12 for the code
post#14 for link to a test page. (I've added the time to the contents for page 1 )

Putting both issues together, there is possibly some glitch with IE and updating form elements.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to AJAX cross-browser problems
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.64068 seconds with 12 queries