| | |
AJAX vs IE issue
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2008
Posts: 7
Reputation:
Solved Threads: 0
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:
Anyone can see what is wrong straight away?
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.
•
•
Join Date: Aug 2008
Posts: 7
Reputation:
Solved Threads: 0
That wasn't it, unfortunately.
It now supports all kinds of different IE things:
But the problem remains.
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.
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
Lost Souls: text based RPG
MUDseek: MUD gaming search
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
Lost Souls: text based RPG
MUDseek: MUD gaming search
•
•
Join Date: Aug 2008
Posts: 381
Reputation:
Solved Threads: 33
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
Fiddled with Ajax page:
Look it over, maybe you'll see what I did
Ciao
Server side script:
remote.php
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<?php print "pizza"; ?>
Fiddled with Ajax page:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<html> <head> <script type="text/javascript"> 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" ); function makePOSTRequest( url, parameters ) { var xmlHttp = null; 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() { // alert( this.status ); if ( this.readyState == 4 ) { //alert( this.responseText ); if ( this.status == 200 ) { result = this.responseText; // document.getElementById('result').innerHTML = result; // document.getElementById('submitbutton').disabled = false; alert( result ); } else { //alert( this.getAllResponseHeaders() ); alert( "There was a problem with the request." ); } } } </script> </head> <body> <a href="javascript:makePOSTRequest('ajax/remote.php','name=value')">Click me please</a> </body> </html>
Look it over, maybe you'll see what I did

Ciao
Last edited by langsor; Aug 14th, 2008 at 9:03 pm.
![]() |
Similar Threads
- IE AJAX issue (JavaScript / DHTML / AJAX)
- Using Ajax.Updater in IE (JavaScript / DHTML / AJAX)
- ajax won't work without the www in url (JavaScript / DHTML / AJAX)
- Urgent help needed regarding executing Scripts in AJAX response (JavaScript / DHTML / AJAX)
- Issue with Javascript embedded in C# (ASP.NET)
- listbox--issue php (PHP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Troubleshoot script
- Next Thread: Ajax and server relation
Views: 2849 | Replies: 14
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
acid2 ajax ajaxcode ajaxhelp animate array automatically autoplay beta boarder box bug button calendar captcha card cart codes column cookies createrange() css cursor date debugger decimal design developer dom download dropdown element enter error events firefox firehose flash focus form frameworks getselection google gwt html htmlform iframe image() index java javascript javascripts jawascriptruntimeerror jquery jsp listbox maps marquee masterpage menu microsoft mimic mp3 mp4 offline onmouseover parameters php player post problem programming progressbar prototype rating redirect regex safari scale scriptlets search select size sources sql starrating text textarea toggle twitter validation variables w3c web website window windowofwords windowsxp xml xspf





