I can not figure out how to use AJAX to post an entire form-- only a variable (i.e. one form field or variable). When 'process.php' receives the data, it says it's a STRING but when I split it, the output mysteriously ONLY states 'Array' so I can't get the data.
Here's what I have:
Code: Select all
<script>
function compress(){
var catter = "";
var elem = document.forms[0].elements[i];
for(i=0; i<document.forms[0].elements.length; i++){
catter += elem.getAttribute("name") + "=" + elem.getAttribute('value') + "&";
}
sendRequest(escape(catter));
}
function sendRequest(what) {
new Ajax.Request("process.php",
{
method: 'post',
postBody: 'data='+what,
onComplete: showResponse
});
}
function showResponse(req){
$('myspan').innerHTML= req.responseText;
}
</script>
Code: Select all
if (isset($_POST)){
$incoming = $_POST['data'];
echo $incoming."<BR>";
echo gettype($incoming)."<BR>";
echo split("&",$incoming)."<BR>";
echo is_string($incoming);
}
What this means is that $incoming is a string but were I to attempt to split by the '&' (the whole point of this) it says 'Array.' This has left me with an unworkable form. I'd ideally be able to POST the whole form but if I could simply split this 'pseudo-string' I could still make this work.txt1=&txt2=&txt3=&
string
Array
1
**** EDIT:::::
I figured something out. Please, someone explain the reasoning behind this but I am able to access it now as an array:
Code: Select all
if (isset($_POST)){
$incoming = $_POST['data'];
$incoming = split("&",$incoming);
print_r($incoming[1]);
}