html
<button id="btn2">show alert array</button>
<button id="btn"> go to php</button>
javascript
var test = new Array();
test.push("one");
test.push("two");
json = JSON.stringify(test);
$('#btn').click(function(){
$.ajax({
type: "POST",
url: "json.php",
data: {data:json}
});
});
$('#btn2').click(function(){
alert(json);
});
php file (json.php)
<?php
$data = json_decode($_POST['data']);
var_dump($data);
?>
id="btn2" is working. It displays an alert with the array on it, but when I click in the id="btn", it is not working at all. Can you tell me the problem of these codes?? I just want to send an array from javascript to php file.