jd2007 Posted August 2, 2007 Share Posted August 2, 2007 ok, below is the page which contains ajax <html> <script type="text/javascript" language="javascript"> function makeRequest(url) { var httpRequest; if (window.XMLHttpRequest) { // Mozilla, Safari, ... httpRequest = new XMLHttpRequest(); if (httpRequest.overrideMimeType) { httpRequest.overrideMimeType('text/xml'); // See note below about this line } } else if (window.ActiveXObject) { // IE try { httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!httpRequest) { alert('Giving up Cannot create an XMLHTTP instance'); return false; } httpRequest.onreadystatechange = function() { alertContents(httpRequest); }; httpRequest.open('POST', url, true); httpRequest.send(''); } function alertContents(httpRequest) { if (httpRequest.readyState == 4) { if (httpRequest.status == 200) { document.write(httpRequest.responseText); } else { alert('There was a problem with the request.'); } } } </script> Name:<input type=text name=name /> <input type=submit value=Display onclick="makeRequest(data.php)" /> and this is the php script data.php: <?php if (empty($_POST["name"]) { echo "Please enter your first name."; } else { echo $_POST["name"]; } ?> when i type my name in text box and click Display...i want it to display my name but what i get is nothing, the page doesn't change...why...pls help ? Quote Link to comment Share on other sites More sharing options...
jd2007 Posted August 2, 2007 Author Share Posted August 2, 2007 another thing, how to display output on the same page. Quote Link to comment Share on other sites More sharing options...
Philip Posted August 2, 2007 Share Posted August 2, 2007 You're not even getting the value from the text field, the code above simply makes a request. Why not take a look at this script/tutorial, it's going to lead you in the right direction: http://www.captain.at/howto-ajax-form-post-request.php 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.