I have a php array
array(6) {
["merchant_id"]=> string(6) "ajeesh"
["passkey"]=> string(4) "1234"
["amt"]=> string(5) "10.00"
["email"]=> string(16) "[email protected]"
["mobileNo"]=> string(10) "9874563210"
["orderID"]=> string(6) "123456"
}
which I got as a result of var_dump($_POST).
How can I copy all this value to a javascript array variable?How can it be possible? Suppose if the javascript array I made is
var thisSession = new Array();
TRY
I have tried this in the javascript
<script>
window.onload = function getApp(){
var thisSession = JSON.parse('<?php echo json_encode($_POST); ?>');
alert (thisSession);
}
</script>
and this in the php
json_encode($_POST);
but the javascript is alerting "Object object".Im not gettign the array!why?
json_encode()function php.net/manual/en/function.json-encode.phpjson_encode+ don't usenew Array();in JS Use the literal notationvar anArray = [];It's shorter and can't result in unexpected behaviour in the same way the constructor can