I have PHP array that I need send to javascript function (for further passing thru ajax) only when a button clicked, so I came up with next idea:
html
<a onclick="notify('<?= json_encode($my_array); ?>','news')" >Send</a>
javascript function
function notify(array, fragment) {
$.ajax({
type: "POST",
url: "../example-api/blabla.php",
data: [{name:"array", array},{name:"fragment",value:fragment}],
success: function(data) {
//Succes
},
});
}
But it doesn't work for me. Do you have any idea why? Ot maybe you know better way than that. Thank you in advence)