View Single Post
Old 09-24-2012, 02:28 PM   PM User | #1
Cobb
New Coder

 
Join Date: Aug 2011
Posts: 20
Thanks: 3
Thanked 0 Times in 0 Posts
Cobb is an unknown quantity at this point
XMLHttp Request problem

I've written a XMLHtttpRequest, but something is breaking down somewhere.

PHP Code:
function submit(){
     
// declaring variables to be used
    
var xhrtargetchangeListenerurldata;

    
//setting url to the php code to add comments to the db
    
url "createCampaign.php";
    
data document.getElementById("source").innerHTML;
    
console.log("Sending"data);

    
// create a request object
    
xhr = new XMLHttpRequest();

    
changeListener = function () {
        if (
xhr.readyState == 4) {
            if (
xhr.status == 200) {
                
console.log("Response"this.responseText);
    
//            result = JSON.parse(this.responseText);
                //injectContent(result.id, form);
            
}
        }
    };

    
// initialise a request, specifying the HTTP method
    // to be used and the URL to be connected to.
    
xhr.onreadystatechange changeListener;
    
xhr.open('POST'urltrue);
    
xhr.setRequestHeader("Content-type""application/x-www-form-urlencoded");
    
xhr.send(data);

    return 
false;

I've tried changing the data variable so that it contains just a simple string but it still does not work.

In the PHP script i'm trying to see if anything has been received by using this line 'echo $_REQUEST['data'];' but it appears that nothing has been sent.

Any help will be greatly appreciated.
Thank you.
Cobb is offline   Reply With Quote