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

Join Date: Aug 2008
Posts: 7
Reputation: Ciubhran is an unknown quantity at this point 
Solved Threads: 0
Ciubhran Ciubhran is offline Offline
Newbie Poster

AJAX vs IE issue

 
0
  #1
Aug 13th, 2008
Hello, I am having problems with Internet Explorer (as always) and AJAX.

My code works with Firefox, but the page returns errors when trying to execute this script in Explorer:

<script type="text/javascript" language="javascript">
   var xmlHttp = false;

   function createPostRequest(url, parameters) {
	if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
      
      	xmlHttp.onreadystatechange = alertContents;
      	xmlHttp.open('POST', url, true);
      	xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
      	xmlHttp.setRequestHeader('Content-length', parameters.length);
      	xmlHttp.setRequestHeader('Connection', "close");
      	xmlHttp.send(parameters);
   }

   function alertContents() {
      if (xmlHttp.readyState == 4) {
         if (xmlHttp.status == 200) {
            result = xmlHttp.responseText;
            document.getElementById('result').innerHTML = result;   
	    document.getElementById('submitbutton').disabled = false;  //re-enable the trigger       
         } else {
            alert("There was a problem with the request.");
         }
      }
   }
   
   function manufacture(obj) {
      document.getElementById('submitbutton').disabled = true;   //disabling the trigger
      var poststr = "out1=" + escape(encodeURI(value1)) + "&out2=" +  escape(encodeURI(value2)) + "&out3=" +  escape(encodeURI(value3)); //there are more variables here, but they are generated with PHP (and the string is created as it should both in IE and FF)

      createPostRequest("manufacture.php", poststr);
   }
</script>

Anyone can see what is wrong straight away?
Last edited by Ciubhran; Aug 13th, 2008 at 9:45 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: AJAX vs IE issue

 
0
  #2
Aug 13th, 2008
I believe xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); is outdated. See how W3Schools suggests implementing for IE. Also, read more about the argument here.
Lost time is never found again.
- Benjamin Franklin
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 7
Reputation: Ciubhran is an unknown quantity at this point 
Solved Threads: 0
Ciubhran Ciubhran is offline Offline
Newbie Poster

Re: AJAX vs IE issue

 
0
  #3
Aug 13th, 2008
That wasn't it, unfortunately.

It now supports all kinds of different IE things:

var XMLHTTPREQUEST_MS_PROGIDS = new Array(
  	"Msxml2.XMLHTTP.7.0",
  	"Msxml2.XMLHTTP.6.0",
 	"Msxml2.XMLHTTP.5.0",
  	"Msxml2.XMLHTTP.4.0",
  	"MSXML2.XMLHTTP.3.0",
  	"MSXML2.XMLHTTP",
  	"Microsoft.XMLHTTP"
   );

   var xmlHttp = null;

   function makePOSTRequest(url, parameters) {
	if (window.XMLHttpRequest != null) {
    		xmlHttp = new window.XMLHttpRequest();
	}
  	else if (window.ActiveXObject != null) {
    		// Must be IE, find the right ActiveXObject.
   		var success = false;
    		for (var i = 0; i < XMLHTTPREQUEST_MS_PROGIDS.length && !success; i++) {
			try {
        			xmlHttp = new ActiveXObject(XMLHTTPREQUEST_MS_PROGIDS[i]);
        			success = true;
      			}
      			catch (ex) {}
    		}
  	}
	else {
		alert("Your browser does not support AJAX.");
		return xmlHttp;
	}
 
      	xmlHttp.onreadystatechange = alertContents;
      	xmlHttp.open('POST', url, true);
      	xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
      	xmlHttp.setRequestHeader('Content-length', parameters.length);
      	xmlHttp.setRequestHeader('Connection', "close");
      	xmlHttp.send(parameters);
   }
	
   function alertContents() {
      if (xmlHttp.readyState == 4) {
         if (xmlHttp.status == 200) {
            result = xmlHttp.responseText;
            document.getElementById('result').innerHTML = result;   
	    document.getElementById('submitbutton').disabled = false;         
         } else {
            alert("There was a problem with the request.");
         }
      }
   }

But the problem remains.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 46
Reputation: chaosprime is an unknown quantity at this point 
Solved Threads: 4
chaosprime's Avatar
chaosprime chaosprime is offline Offline
Light Poster

Re: AJAX vs IE issue

 
0
  #4
Aug 14th, 2008
As always: how does it fail? What happens, how does that differ from your expectations, what debugging information do you get? (Tip: go to Tools > Internet Options, Advanced tab, and make sure "Browsing: Display a notification about every script error" is on and "Browsing: Disable script debugging (Internet Explorer)" and "Browsing: Disable script debugging (Other)" are off.)
Chaos
Lost Souls: text based RPG
MUDseek: MUD gaming search
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 7
Reputation: Ciubhran is an unknown quantity at this point 
Solved Threads: 0
Ciubhran Ciubhran is offline Offline
Newbie Poster

Re: AJAX vs IE issue

 
0
  #5
Aug 14th, 2008
Object doesnt support this property or method.

If my inferior debugging skills serve me right, its on the same line as send().
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 46
Reputation: chaosprime is an unknown quantity at this point 
Solved Threads: 4
chaosprime's Avatar
chaosprime chaosprime is offline Offline
Light Poster

Re: AJAX vs IE issue

 
0
  #6
Aug 14th, 2008
If you can't tell by matching the reported line number with your code, then insert alert()s for debugging. For instance, if you put one before and one after the send() call, and the first alert() fires and the second doesn't, then you know it was in fact the send() call. If neither alert fires, it's earlier. If both alerts fire, madness ensues.
Chaos
Lost Souls: text based RPG
MUDseek: MUD gaming search
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 381
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 33
langsor langsor is offline Offline
Posting Whiz

Re: AJAX vs IE issue

 
0
  #7
Aug 14th, 2008
I just spent some time fooling around with this and not realizing that my path to my server-side script wasn't being found by the server (on my local computer)...when i fixed that it just worked -- I don't know what I did. It's working on my computer for IE 7, FF 3, Opera 9.51.

Server side script:
remote.php
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?php
  2. print "pizza";
  3. ?>

Fiddled with Ajax page:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4.  
  5. var XMLHTTPREQUEST_MS_PROGIDS = new Array(
  6. "Msxml2.XMLHTTP.7.0",
  7. "Msxml2.XMLHTTP.6.0",
  8. "Msxml2.XMLHTTP.5.0",
  9. "Msxml2.XMLHTTP.4.0",
  10. "MSXML2.XMLHTTP.3.0",
  11. "MSXML2.XMLHTTP",
  12. "Microsoft.XMLHTTP"
  13. );
  14.  
  15. function makePOSTRequest( url, parameters ) {
  16. var xmlHttp = null;
  17. if ( window.XMLHttpRequest != null ) {
  18. xmlHttp = new window.XMLHttpRequest();
  19. } else if ( window.ActiveXObject != null ) {
  20. // Must be IE, find the right ActiveXObject.
  21. var success = false;
  22. for (var i = 0; i < XMLHTTPREQUEST_MS_PROGIDS.length && !success; i ++) {
  23. try {
  24. xmlHttp = new ActiveXObject(XMLHTTPREQUEST_MS_PROGIDS[i]);
  25. success = true;
  26. } catch (ex) {}
  27. }
  28. } else {
  29. alert( "Your browser does not support AJAX." );
  30. return xmlHttp;
  31. }
  32. xmlHttp.onreadystatechange = alertContents;
  33. xmlHttp.open( 'POST', url, true );
  34. xmlHttp.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' );
  35. xmlHttp.setRequestHeader( 'Content-length', parameters.length );
  36. //xmlHttp.setRequestHeader('Connection', "close");
  37. xmlHttp.send( parameters );
  38. }
  39.  
  40. function alertContents() {
  41. // alert( this.status );
  42. if ( this.readyState == 4 ) {
  43. //alert( this.responseText );
  44. if ( this.status == 200 ) {
  45. result = this.responseText;
  46. // document.getElementById('result').innerHTML = result;
  47. // document.getElementById('submitbutton').disabled = false;
  48. alert( result );
  49. } else {
  50. //alert( this.getAllResponseHeaders() );
  51. alert( "There was a problem with the request." );
  52. }
  53. }
  54. }
  55. </script>
  56. </head>
  57. <body>
  58. <a href="javascript:makePOSTRequest('ajax/remote.php','name=value')">Click me please</a>
  59. </body>
  60. </html>

Look it over, maybe you'll see what I did

Ciao
Last edited by langsor; Aug 14th, 2008 at 9:03 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 7
Reputation: Ciubhran is an unknown quantity at this point 
Solved Threads: 0
Ciubhran Ciubhran is offline Offline
Newbie Poster

Re: AJAX vs IE issue

 
0
  #8
Aug 15th, 2008
I pretty much copied your example, still doesn't work.

And now my debugger says its on "open()"...

But, adding alerts() on places around it, the place of error changes to the alert...

So I don't know what is up with the IE script debugger.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 7
Reputation: Ciubhran is an unknown quantity at this point 
Solved Threads: 0
Ciubhran Ciubhran is offline Offline
Newbie Poster

Re: AJAX vs IE issue

 
0
  #9
Aug 15th, 2008
PROBLEM SOLVED!

God, that was so easy.

The error was that I never declared 'result' as a variable.

It was:

"result = this.responseText"

which I simply changed to

"var result = this.responeText"

The variable isnt even needed, don't know why it is there.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 7
Reputation: Ciubhran is an unknown quantity at this point 
Solved Threads: 0
Ciubhran Ciubhran is offline Offline
Newbie Poster

Re: AJAX vs IE issue

 
0
  #10
Aug 15th, 2008
Found another problem now.

If I declare "var xmlHttp" as a global, it only works in FF. If I declare it inside of makePOSTRequest (like the above example), then it only works in IE.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
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