What is wrong with this code: I am getting any return values from PHP 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> Code (markup): 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>"; ?> Code (markup):
Your ajax code and initialization could be better. I rewrote it: function ajax() { var url = "AjaxCall.php"; // The server-side script 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; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { alert(xmlHttp.responseText); } } xmlHttp.open("GET",url,true); xmlHttp.send(null); } PHP: However just for your info you shouldn't use AJAX if all you want is a table. This makes more sense: alert("<table border='1'><tr><th>Firstname</th><th>Lastname</th><th>Age</th><th>Hometown</th><th>Job</th></tr><tr><td></td></tr></table>") PHP: