AJAX Not working with IE6-IE8 Browsers

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

Join Date: Mar 2008
Posts: 36
Reputation: lonestar23 is an unknown quantity at this point 
Solved Threads: 0
lonestar23 lonestar23 is offline Offline
Light Poster

AJAX Not working with IE6-IE8 Browsers

 
0
  #1
Apr 30th, 2009
Have been trying to figure this one out for some time, but still can not get this AJAX script to work with Internet Explorer. It works with all other browsers. Thanks in Advance!

FORM CODE
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script language="JavaScript" type="text/javascript" src="aj.js">
  2. </script>
  3. <input type="text" value="#CCC" id="paints" size="7">
  4. <input type="button" value="submit" id="gColor" onclick=
  5. "handleIT();colorIT()"> <input type="text" id="textBack">
  6. <div class="c1" id="divBack">Dynamically Paint Here.</div>

aj.php CODE
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?php
  2. $paint = trim($_POST['paints']);
  3. echo trim($paint);
  4. ?>

aj.js AJAX POST CODE
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function getXmlHttpRequestObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest();} else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP");} else {}}
  2.  
  3. var search7 = getXmlHttpRequestObject();
  4.  
  5. function handleIT() { if (search7.readyState == 4 || search7.readyState == 0) {
  6.  
  7. var paints = escape(document.getElementById('paints').value);
  8. var parameters="paints="+paints;
  9.  
  10. search7.open("POST", 'aj.php', true);
  11. search7.onreadystatechange = colorIT;
  12.  
  13. search7.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  14. search7.send(parameters);
  15. }}
  16.  
  17. function colorIT() { if (search7.readyState == 4) {
  18. var paints = escape(document.getElementById('paints').value);
  19.  
  20. document.getElementById("textBack").value=search7.responseText;
  21. document.getElementById("divBack").style.backgroundColor=search7.responseText;
  22. }}
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: AJAX Not working with IE6-IE8 Browsers

 
0
  #2
Apr 30th, 2009
Try the following format:

aj.js

  1. var paints, parameters, search7, colorIT;
  2.  
  3. colorIT = function() {
  4. if ( search7.readyState === 4 ) {
  5. document.getElementById("textBack").value = search7.responseText;
  6. document.getElementById("divBack").style.backgroundColor = search7.responseText;
  7. }
  8. };
  9.  
  10. function getXmlHttpRequestObject() {
  11. search7 = null;
  12. paints = escape( document.getElementById("prints").value );
  13. parameters = "paints=" + paints;
  14. if ( window.XMLHttpRequest ) {
  15. search7 = new XMLHttpRequest();
  16. } else if ( window.ActiveXObject ) {
  17. try {
  18. search7 = new ActiveXObject("Microsoft.XMLHTTP");
  19. } catch( e ) {
  20. search7 = new ActiveXObject("Msxml2.XMLHTTP");
  21. }
  22. }
  23. if ( search7 !== null ) {
  24. search7 = ( search7.overrideMimeType ) ? search7.overrideMimeType("text/xml") : search7;
  25. search7 = ( search7.setRequestHeader ) ? search7.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") : search7;
  26. search7.onreadystatechange = colorIT;
  27. search7.open("POST", "aj.ph", true);
  28. search7.send( parameters );
  29. } else {
  30. alert("\nYour browser does not support AJAX Request!");
  31. }
  32. }

Let me know, if you're still getting the same issue...
Last edited by essential; Apr 30th, 2009 at 11:00 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 36
Reputation: lonestar23 is an unknown quantity at this point 
Solved Threads: 0
lonestar23 lonestar23 is offline Offline
Light Poster

Re: AJAX Not working with IE6-IE8 Browsers

 
0
  #3
May 1st, 2009
The code I originally posted works in function but according to the Internet Explorer Team they found.

===== IE Team Response =====
From an analysis of the IE folks, it seems that the problem is generated by some whitespace in your string

00380023 00380038 0000000a

This fails:
document.getElementById("divBack").style.backgroundColor=search7.responseText;
Error is Invalid property value.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: AJAX Not working with IE6-IE8 Browsers

 
0
  #4
May 1st, 2009
Just disregard my post, if your code is working...
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 36
Reputation: lonestar23 is an unknown quantity at this point 
Solved Threads: 0
lonestar23 lonestar23 is offline Offline
Light Poster

Re: AJAX Not working with IE6-IE8 Browsers

 
0
  #5
May 1st, 2009
The code does not work, because of some weird whitespace being passed that is what microsoft said. YOu can see the code in function at the below url. It works with all browsers except Internet Explorer.

http://89.233.173.91/bug/

The sample is running the code originally posted on this thread.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: AJAX Not working with IE6-IE8 Browsers

 
0
  #6
May 1st, 2009
Try not to escape the string being passed by the paints object, and see how things will work...
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 36
Reputation: lonestar23 is an unknown quantity at this point 
Solved Threads: 0
lonestar23 lonestar23 is offline Offline
Light Poster

Re: AJAX Not working with IE6-IE8 Browsers

 
0
  #7
May 1st, 2009
you can see the original code behavior at the following http://89.233.173.91/bug/ It works with any browser except IE. Have tried not escaping and get the same error....
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: AJAX Not working with IE6-IE8 Browsers

 
0
  #8
May 1st, 2009
Would you prefer using a different method?

How about a function that will filter a user input, then set it as direct style of the object?
Example:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. if ( document.all ) {
  2. div = document.all.divBack;
  3. div.setAttribute("style", "background-color : " + search7.responseText + ";");
  4. }
Im sure there's a way to defeat the bug...
Just try to play some experiment in your function's.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



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