Page 1 of 1

PHP Paramaters lost

Posted: Tue Aug 24, 2010 9:22 am
by royalprotection
I am having some issues and I cannot figure out the problem. My parameters are being sent via an XMLHttpRequest() and I can view that they are sent using Firebug. When I try and print them out using a PHP script, they are always blank. Everything I have read about PHP says I am doing this correctly. Here is my javascript:


function saveData()
{
url = "saveEvents.php"
var outputData = "TESTING OUTPUT";

xmlhttp = false;

// branch for native XMLHttpRequest object
if(window.XMLHttpRequest && !(window.ActiveXObject)) {
try {
xmlhttp = new XMLHttpRequest();
} catch(e) {
xmlhttp = false;
}
// branch for IE/Windows ActiveX version
} else if(window.ActiveXObject) {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
xmlhttp = false;
}
}
}

if(xmlhttp) {
xmlhttp.open("POST", url, false);

//Send the proper header information along with the request
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", outputData.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.onreadystatechange = function() {//Call a function when the state changes.

if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
alert(xmlhttp.responseText);
}

xmlhttp.send("data=" + outputData);
}
}


And here is my PHP code(saveEvents.php):

Code: Select all


<?php 
$File = "events.txt"; 
$Handle = fopen($File, 'w'); 
$Data = $_POST['data']; 
fwrite($Handle, $Data);  
print "Data Added: data=".$Data; 
fclose($Handle); 
?>


What I get is this:

Data Added: data=
Nothing gets written to the text file either. Am I missing something here?

Re: PHP Paramaters lost

Posted: Tue Aug 24, 2010 2:05 pm
by JakeJ
I'm not real clear on this.. are you sending a form? It could just be that you have bad form data to begin with.

Also, while this doesn't fix whatever technical problem you have, you might just be better off using jQuery so you don't have to mess with all of that stuff. jQuery form plug in is great and seems to be flawless.