Jump to content

Help needed on AJAX with PHP


kks_krishna

Recommended Posts

What is wrong with this code:

Html code

<script type="text/javascript"> 
		var url = "AjaxCall.php"; // The server-side script
		 var xmlhttp;
		function handleHttpResponse() {   
			alert(6);
        if (xmlhttp.readyState == 4) {
			alert(7);
			var results=xmlhttp.responseText;
			alert(results);
			if(xmlhttp.status==200) {
                  var results=xmlhttp.responseText;
			  alert(5);
			  alert(results);
			}
		  }
	    } 
		function requestCustomerInfo() {     
			//var sId = document.getElementById("txtCustomerId").value;
			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>

 

 

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
Share on other sites

what are you trying to achieve,  the javascript is fine except you got to-many alerts, please remove all this alerts except alert(results);, secondly i don't see how you are calling the requestCustomerInfo() function.

 

If you are using a separte file and calling this function.  please show the file.    I mean you should be calling requestCustomerInfo() from somewhere?

Link to comment
Share on other sites

Here is the code to call that method :

 

<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>

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.