I am having an issue with AJAX posting data to PHP and I can't for the life of me figure out what the problem is.
Here is the section of code dealing with the xmlhttprequest...
if(str != null && str.length > 0) {
var http = new XMLHttpRequest();
var site = 'URL here';
var strContent = 'text='+escape(str);
http.open('POST', site, true);
http.onreadystatechange = ReadyStateChange;
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
http.send(strContent);
}
The problem I am having is this does not seem to be doing anything. I am not receiving any javascript errors, but at the same time the database does not appear to be updating either. When the string comes into php am I correct in thinking that it should originally come in as...
$_POST['text']
That is how I am expecting the text to arrive into my php file but nothing changes in my database. I am not great with javascript, and totally new to AJAX but it was the only javascript that I know of that will submit data to php.
If anyone has any help or tips on this I would appreciate it, I've spent the last 3 days trying various codes from the net and they all do the same thing.
Is there something I need to initialize in PHP to read the xmlhttprequest? Perhaps it is as simple as that and I am working on trying to fix an issue that doesn't exist.
Thanks.