I cannot figure this out for the life of me.
I am trying to pass a single array to a php script processData.php that will then use that data in order to execute a perl script.
I then want to return the results of the perl script back to JQUERY for display.
It looks like when I try to display the data back, the data comes back as a NULL value.
JQUERY PAGE:
$('#numDevices').click(function(event) {
event.preventDefault();
var test = [];
var $number = $('#element');
var value = $number.val();
var container = $('#main');
$('.device').remove();
$('#send').remove();
for(var i=0; i<value; i++) {
container.append('<div class="device"><fieldset><legend>Device' + i + '</legend><textarea class="input" rows="10">Please enter a hostname, followed by the corresponding links.</textarea></fieldset></div>');
}
container.append('<input type="submit" id="send" name="send" value="submit"/>');
$('#send').click(function(event) {
event.preventDefault();
var device = new Array();
$('textarea').each(function(index, area) {
var $area = $(area).val();
device.push($area);
});
$.ajax({
type: "GET",
url: "processData.php",
data: "input"+device,
cache: false,
success: function(data) {
alert(data);
},
error: function() {
alert("FAILED");
}
});
});
});
.....
PHP PAGE:
<?php
$data =$_GET['input'];
echo json_encode($data);
?>
So as you can see, to test, I am trying to pass an array to php, and then pass it back to JQUERY for display. I am getting a NULL value when I pass back, so I can only assume I am sending a NULL value.
If more information is needed I will gladly add it.
UPDATE
1) I have changed
data: "input"+device, to
data: {input: device},
I can now see the value via var_dump($data);
The problem I am having now is that the data being sent back to JQUERY is NULL.
SECOND UPDATE
1) Added: dataType: "json"
2) Changed GET to POST
New Error: 1) Parsererror 2) unexpected end of input 3) [Object][Object]