Jump to content

Why this code is not working?


kks_krishna

Recommended Posts

HI,

 

Please see this code. Its not returning any value.

 

Java Script

 

<script type="text/javascript"> 
		var url = "AjaxCall.php"; // The server-side script
		 var xmlhttp;
		function handleHttpResponse() {   
        if (xmlhttp.readyState == 4) {
			var results=xmlhttp.responseText;
			alert(results);
			if(xmlhttp.status==200) {
                  var results=xmlhttp.responseText;
			  alert(5);
			  alert(results);
			}
		  }
	    } 
		function requestCustomerInfo() {     
			xmlhttp = getHTTPObject();
			xmlhttp.open("GET", url, true);
			xmlhttp.onreadystatechange = handleHttpResponse;
			xmlhttp.send(null);
		}
		function getHTTPObject() {
		     
			  if(window.XMLHttpRequest){
				xmlhttp = new XMLHttpRequest();
			  }
			  else if (window.ActiveXObject){
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
				if (!xmlhttp){
					xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
				}
   				}
			return xmlhttp;
		} 
	</script>

 

 

HTMl form

 

 

<form name="comment_form" action="">
				<table  width="100%">
					<tr>
						<td>
							Add your comments
						</td>
					</tr>
					<tr>
						<td>
							<textarea name="comments" cols="40" rows="5"></textarea>
						</td>
					</tr>
					<tr>
						<td>
							<input type="submit" value="Add Comment" onclick="requestCustomerInfo()">
						</td>
					</tr>
				</table>
				<input type="hidden" name="op" value="comment">
			</form>

 

 

AjaxCall.php

 

<?php

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
</tr>";
echo "<tr>";
echo "<td></td>";
echo "</tr>";
echo "</table>";
?>

Link to comment
https://forums.phpfreaks.com/topic/59651-why-this-code-is-not-working/
Share on other sites

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.