Jump to content

xmlHttp.responseText has no value


RIRedinPA

Recommended Posts

I'm not getting any returned values from my php page. Not sure what I am doing wrong here. I'm basically repurposing code that is working.

 

Javascript:

 

var xmlHttp = checkajax(); 
			xmlHttp.onreadystatechange=function() {
    				if(xmlHttp.readyState==4) {
					var returneditem = xmlHttp.responseText;
					alert(returneditem);
				}
			}
		xmlHttp.open("GET","editissue.php?", true);
  			xmlHttp.send(null);

 

PHP (editissue.php)

 

<?php 
echo "what the heck?";
?>

 

The Javascript alert displays no value. Like I said, I am using the same exact code in other areas to return a lot of php code so I'm at a loss as to explain why it is not working here. Any help would be mucho appreciated.

 

checkajax function

 

function checkajax() {
//ajax compatibility check
	var xmlHttp;
	try {
  			// Firefox, Opera 8.0+, Safari
  			xmlHttp=new XMLHttpRequest();
  		}
		catch (e) {
  			// Internet Explorer
  			try {
    			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    		}
  				catch (e) {
    			try {
      				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      			}
    				catch (e) {
      				alert("Your browser does not support AJAX!");
      				return false;
      			}
    		}
  		}

	return xmlHttp
}

Link to comment
Share on other sites

grrr....

 

same code, pulled out and dumped into a test page works fine:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>AJAX Test</title>

<script language="javascript">

function ajaxtest() { 

var xmlHttp = checkajax(); 
			xmlHttp.onreadystatechange=function() {
    				if(xmlHttp.readyState==4) {
					var returneditem = xmlHttp.responseText;
					document.getElementById('msg').innerHTML = returneditem
				}
			}
		xmlHttp.open("GET","editissue.php?", true);
  			xmlHttp.send(null);

}

function checkajax() {
//ajax compatibility check
	var xmlHttp;
	try {
  			// Firefox, Opera 8.0+, Safari
  			xmlHttp=new XMLHttpRequest();
  		}
		catch (e) {
  			// Internet Explorer
  			try {
    			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    		}
  				catch (e) {
    			try {
      				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      			}
    				catch (e) {
      				alert("Your browser does not support AJAX!");
      				return false;
      			}
    		}
  		}

	return xmlHttp
}
</script>

</head>

<body>

<div id="button"  style="background-color: #CC6600; color: #fff; width: 300px; height: 30px; text-align: center; padding: 3px;"><a href="javascript:void(0)" onmousedown="ajaxtest()" style="text-decoration: none; color: #660033; letter-spacing: .6em; ">Click</a></div>
<div id="msg" style="position: absolute; top: 200px; left: 200px; background-color: #FFCC33; color: #333; width: 400px; height: 400px; text-align: center; vertical-align: middle; border: 1px solid #FF6600; "> </div>
</body>
</html>

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.