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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.