My head hurts.
ajax.responseText returns the echo back to the original script. Is it possible to execute displayRec.php, passing keyid via $_POST, as an HTML POST form would behave, or must it always be returned?
WHAT? I don't understand the question, at all.
We *ARE* using AJAX to execute displayRec.php
. We *ARE* passing the keyid via $_POST. In what what way is this *NOT* what an HTML POST would do?
I don't know what "returns the echo" means. What exactly are you seeing in that alert of the responseText??
I do see I missed one thing in my AJAX code. I forgot to set the Content-Type to allow POST. Is that the problem?
It should be
function ajax_post( )
var ajax = window.XMLHttpRequest != null
? new XMLHttpRequest()
: new ActiveXObject("Microsoft.XMLHTTP");
ajax.open( "POST", "displayRec.php", true );
if (ajax.readyState==4 && ajax.status==200)
alert("Answer from AJAX: " + ajax.responseText );
ajax.send("keyid=" + keyid );
Apologies if that's the only problem. I use GET for virtually all my AJAX stuff, so I tend to forget about content-type (not used with GET).