943,694 Members | Top Members by Rank

Ad:
Apr 30th, 2009
0

AJAX Not working with IE6-IE8 Browsers

Expand Post »
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. }}
Reputation Points: 20
Solved Threads: 0
Light Poster
lonestar23 is offline Offline
43 posts
since Mar 2008
Apr 30th, 2009
0

Re: AJAX Not working with IE6-IE8 Browsers

Try the following format:

aj.js

javascript Syntax (Toggle Plain Text)
  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.
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
May 1st, 2009
0

Re: AJAX Not working with IE6-IE8 Browsers

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.
Reputation Points: 20
Solved Threads: 0
Light Poster
lonestar23 is offline Offline
43 posts
since Mar 2008
May 1st, 2009
0

Re: AJAX Not working with IE6-IE8 Browsers

Just disregard my post, if your code is working...
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
May 1st, 2009
0

Re: AJAX Not working with IE6-IE8 Browsers

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.
Reputation Points: 20
Solved Threads: 0
Light Poster
lonestar23 is offline Offline
43 posts
since Mar 2008
May 1st, 2009
0

Re: AJAX Not working with IE6-IE8 Browsers

Try not to escape the string being passed by the paints object, and see how things will work...
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
May 1st, 2009
0

Re: AJAX Not working with IE6-IE8 Browsers

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....
Reputation Points: 20
Solved Threads: 0
Light Poster
lonestar23 is offline Offline
43 posts
since Mar 2008
May 1st, 2009
0

Re: AJAX Not working with IE6-IE8 Browsers

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.
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: can't call this function...
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Swapping data from textbox1 to textbox2 & textbox2 to textbox1 in 1 onclick event





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC