squiblo Posted April 15, 2010 Share Posted April 15, 2010 I am trying to post data to another page (i am trying to make my own shoutbox/chat sort of thing) without refreshing the page, I have done some research and found a few scripts and tried to mix them together and I have come up with the following shown below, my problem is that the data does not even send. ajax.js var xmlhttp; function showUser() { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var content = "bghkefgrgy"; xmlhttp.open("POST","http://localhost/test/response.php", true); xmlhttp.setRequestHeader("content-type","application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("content-length", content.length); xmlhttp.setRequestHeader("connection","close"); xmlhttp.send(content); } function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("response").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } index.php <html> <head> <script type="text/javascript" src="http://localhost/test/ajax.js"></script> </head> <body> <form> <input type='button' value='send' onclick="showUser();"> </form> <div id='response'></div> </body> </html> response.php <?php print_r($_SERVER); ?> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 And how exactly do you know that the data isn't being sent? For the record, your stateChanged function is never called. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.