I am attempting to pass an array to php via ajax from jquery, yet its returning nothing in the html return in the alert on success from the ajax.
When setting the type of ajax send to json the ajax fails completely, so i have kept it to html as it returns the php page at least.
How do i manage this array on the php end?
The JS/JQ
var multi = $('.till__tablepanel_table_' + tablenumber + '_row__ticket');
var myarray = [];
$.each(multi, function (index, item) {
myarray.push({
name: 'ticket_row_num',
value: $(item).data('ticket_row_num')
});
myarray.push({
name: 'itemtitle',
value: $(item).data('itemtitle')
});
myarray.push({
name: 'row_itemid',
value: $(item).data('row_itemid')
});
myarray.push({
name: 'row_quantity',
value: $(item).data('row_quantity')
});
myarray.push({
name: 'rowunitprice',
value: $(item).data('rowunitprice')
});
myarray.push({
name: 'row_total',
value: $(item).data('row_total')
});
myarray.push({
name: 'measure_type_is_grams',
value: $(item).data('measure_type_is_grams')
});
});
//alert(JSON.stringify(myarray));
var url = "http://www.thepantrybromley.com/home/secure/bin/updateDatabase_items.php";
$.ajax({
type: 'POST',
url: url,
dataType: 'html',
data: {
myarray: myarray
},
beforeSend: function () {
// alert("before send");
},
success: function (html) {
alert(html);
}
});
The PHP
<?
$array=json_decode($_POST['myarray']);
echo $array;
?>
array()currentlyjsonbefore sending and decode it at the end . That would be right .