AJAX in IE malfunction

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Aug 2009
Posts: 81
Reputation: Graphix is an unknown quantity at this point 
Solved Threads: 18
Graphix's Avatar
Graphix Graphix is offline Offline
Junior Poster in Training

AJAX in IE malfunction

 
0
  #1
Sep 15th, 2009
Hi,

I am currently writing a chatprogram, and it works fine in FF but it doesnt refresh as it should every 1500ms (set with setInterval("retrieve_messages()",1500) in body tag) in IE. The object ajax is made in previous code.

I wrote the following code:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function retrieve_messages() {
  2. // Checks wether the object is available:
  3. if (ajax) {
  4. ajax.open('get', 'messageretrieve.php');
  5.  
  6. // Sends request
  7. ajax.send(null);
  8.  
  9. // Function that handles response
  10. ajax.onreadystatechange = setTimeout("show_messages()", 500);
  11.  
  12.  
  13. } else { // AJAX is not useable
  14. document.getElementById('warning').innerHTML = 'It is not possible to connect, please update your browser.';
  15. }
  16.  
  17. } // End of retrieve_messages()
  18. // Function that shows the returned text into the messagebox
  19. function show_messages() {
  20. // If everything is OK:
  21. if ( (ajax.readyState == 4) && (ajax.status == 200) ) {
  22. // Returns the value to the document
  23. document.getElementById('messagebox').innerHTML = ajax.responseText;
  24. }
  25.  
  26. } // End of function show_messages()

IE says that there is something not implemented on line 9 (ajax.onreadystatechange=.....), could somebody help me out?

~Graphix

EDIT: I am currently going to bed, i will be back tomorrow.
Last edited by Graphix; Sep 15th, 2009 at 3:59 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 862
Reputation: Airshow is on a distinguished road 
Solved Threads: 122
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: AJAX in IE malfunction

 
1
  #2
Sep 16th, 2009
Try,

  1. ajax.onreadystatechange = function(){setTimeout("show_messages()", 500);}
It is also good practise to establish the response handler before sending the request, so put lines 9/10 above 6/7.

Airshow
Last edited by Airshow; Sep 16th, 2009 at 7:55 am.
50% of the solution lies in accurately describing the problem!
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 81
Reputation: Graphix is an unknown quantity at this point 
Solved Threads: 18
Graphix's Avatar
Graphix Graphix is offline Offline
Junior Poster in Training

Re: AJAX in IE malfunction

 
0
  #3
Sep 17th, 2009
Ok thank you, it worked . But i also have another question, i have a small problem with my chat-program: if the users presses enter it will reload and it will log out due to the onunload="leave_chat()" part. But if i delete the form i cant referer to the text input and as so cant retrieve the value typed in the textbox.

Eg:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <body onload="setInterval('retrieve_users()', 1500); setInterval('retrieve_messages()', 1500)" onunload="leave_chat()">
  2. ....
  3. .... not relevant HTML
  4. .....
  5. <form method="post" name="sendform" action="defaultchat.php">
  6. <input type='text' name='textbox' id='textbox' maxlength='255' size='75' /><input type='button' value='Send Message' onclick='send_message()' />
  7. </form>
Last edited by Graphix; Sep 17th, 2009 at 11:44 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 862
Reputation: Airshow is on a distinguished road 
Solved Threads: 122
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: AJAX in IE malfunction

 
0
  #4
Sep 17th, 2009
Graphix,

You need to suppress the form's natural tendency to want to be submitted when a field has focus and user hits enter. That's fairly simple to cure because the form (as far as I can see) never needs to be submitted. Two options immediately come to mind:

1. Reduce the <form ...> tag to <form>, and call send_message with
onclick='send_message(this.form.textbox.value)' to make the user-entered text available as an argument to the function.

2. Leave the form tag in place but change it to :
  1. <form name="sendform" onsubmit="return false;">
onsubmit="return false;" ensures that the form will not be submitted, whilst your button's onclick="send_message()" will still work.

Goood luck

Airshow
Last edited by Airshow; Sep 17th, 2009 at 1:48 pm.
50% of the solution lies in accurately describing the problem!
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 81
Reputation: Graphix is an unknown quantity at this point 
Solved Threads: 18
Graphix's Avatar
Graphix Graphix is offline Offline
Junior Poster in Training

Re: AJAX in IE malfunction

 
0
  #5
Sep 19th, 2009
Thanks for help, I completed the chat-program and it works perfectly.

Thread Solved

~Graphix
Reply With Quote Quick reply to this message  
Reply

Tags
ajax, error, onreadystatechange

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC