javascript - PHP & Jquery Ajax, json, get data in the ajax destination file -
i need send array in php trough ajax different server, trying following.
array encoded json_encode
:
[ {"id":"1","name":"avocado toast tartine","qty":"1","price":"88.00","spec":""}, {"id":"16","name":"add berries","qty":"1","price":"48.00","spec":""} ]
so in origin file have:
<script> var cart = <?php echo $cart; ?>; //this array above $.ajax({ url: 'https://www.mydestinationurl.com.hk/new/admin/do_lpq_order.php', crossdomain: true, type: 'post', data: cart }).done(function(data) { console.log(data); }); </script>
and in destination file have this:
<?php switch ($_server['http_origin']) { case 'http://localhost': case 'https://localhost': header('access-control-allow-origin: '.$_server['http_origin']); header('access-control-allow-methods: get, put, post, delete, options'); header('access-control-max-age: 1000'); header('access-control-allow-headers: content-type, authorization, x-requested-with'); break; } print_r($_post); ?>
but when see log check data sent get:
array ( [avocado_toast_tartine] => [add_berries] => )
is have lost lot of information. how can total json array
use in php?
Comments
Post a Comment