通过ajax工具向js发送数组请求
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过ajax工具向js发送数组请求相关的知识,希望对你有一定的参考价值。
Send array through ajax tools request to js
$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>
以上是关于通过ajax工具向js发送数组请求的主要内容,如果未能解决你的问题,请参考以下文章