Jump to content

Ajax: parameter passing not working on IE


jchoi1009

Recommended Posts

I have this simple code to test something:

 

<?php
if (isset($_POST['c'])){
echo $_POST["c"];
return;
}
?>

<html>
<head>
	<script type="text/javascript">
	<!--
		function ajax(){
			var activexmodes=["Microsoft.XMLHTTP","Msxml2.XMLHTTP"]; //activeX versions to check for in IE
			if (navigator.appName == "Microsoft Internet Explorer" && window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
				for (var i=0; i<activexmodes.length; i++){
					try{
						return new ActiveXObject(activexmodes[i]);
					}
					catch(e){
						//suppress error
					}
				}
			}
			else if (window.XMLHttpRequest) // if Mozilla, Safari etc
				return new XMLHttpRequest();
			else
				return;
		}
		function sendIt(){
			var xml = new ajax();
			var params = "c="+encodeURI(document.getElementById("c").value);
			xml.open("POST", "test.php", true);
			xml.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
			xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xml.setRequestHeader("Content-length", params.length);
			xml.setRequestHeader("Connection", "close");
			xml.onreadystatechange = function(){
				if (xml.readyState == 4){
					document.getElementById('r').innerHTML = xml.responseText;
				}
			};
			xml.send(params);
		}
	//-->
	</script>
</head>
<body>
	<div id="r" style="font-size:15pt">
		HERE
	</div>
	<input type="text" id="c" />
	<input type="button" value="Submit" onclick="sendIt()" />
</body>
</html>

 

It works flawlessly on Firefox, but on IE, the php is not receiving any parameter ($_POST['c'] is empty always). I tried both POST and GET methods.

 

Please help me.

Much appreaciated.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.