/ Published in: PHP
Send array through ajax tools request to js
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$array //has our data //in the tools file array_walk ($array, 'utf8_encode_array'); //could lead to UTF-8 problems.. echo json_encode($array); function utf8_encode_array (&$array, $key) { //encodes the array recursively to utf8 if(is_array($array)) { array_walk ($array, 'utf8_encode_array'); } else { $array = utf8_encode($array); } } /*********************************************/ //Ajax request to the tools file: ?> <script type="text/javascript"> $.ajax({ type: "POST", url: '<?php echo Loader::helper('concrete/urls')->getToolsURL('path_to_tools_file.php', 'packagename_or_empty'); ?>', data: data, //send data as POST (data is an object) success: function(msg) { try { var myObj = jQuery.parseJSON(msg); myObj.images; myObj.name; myObj.text[0 .. n]; }catch(e){ alert(e.error); } } }); </script>