I want to send a JavaScript array to the server when a user clicks on a button.
My current code is as follows, but it does not work, could someone help me with this?
HTML
<?
$arrs = {include for database}
$js_array = json_encode($arrs);
?>
<script>
var dataArray = <?php echo $js_array; ?>;
var jsData = JSON.stringify(dataArray);
$.ajax({
type: "POST",
url: "savepos.php",
datatype: "JSON",
data: {data : jsData},
success: function() {
alert('success!');
}
});
</script>
savepos.php
$data_array = json_decode(stripslashes($_POST['data']));
However, I get $data_array
as null ?