This question already has an answer here:
Send POST data using XMLHttpRequest
This might help:
ajaxRequest.open("POST","dat.php", true); ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); ajaxRequest.send("q="+str);
Take a look at this page.
Right now, you're sending a post request with nothing in it. Appending to the url just changes the $_GET variables.
You are mixing
POST Ajax call with
When you send an AJAX call with POST, you don't have to put parameter on the URL, but you must send parameters using the
ajaxRequest.open("POST","dat.php",true); ajaxRequest.send("q=" + str);
You should use a JS librairy like jQuery or other, that will make it for you, instead of re-inventing the wheel and have common problems.