通过jquery发送PHP数组的最佳方法是什么? [英] What is the best way to send PHP array via jquery?
本文介绍了通过jquery发送PHP数组的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以帮助解释或提供有关如何在jquery中发送多个数组(或仅是array)的数组的参考.以及当某件事失败或成功时最好的方法是什么.我的意思是php代码如何发送成功或失败的消息
can anybody help to explain or give reference on how to send array of multiple array (or just array ) in jquery. and what the best way to do when something is failed or successfull. what i mean is how the php code send back the success or failed message
推荐答案
使用 JSON ENCODE
类似这样的东西:
index.php
<script type="text/javascript" src="jsfile.js"></script>
<a href='numbers.php' class='ajax'>Click</a>
numbers.php
<?php
$arr = array ( "one" => "1", "two" => "2", "three" => "3" ); // your array
echo json_encode( $arr ); // encode it to json
?>
jsfile.js
jQuery(document).ready(function(){
jQuery('.ajax').live('click', function(event) {
event.preventDefault();
jQuery.getJSON(this.href, function(snippets) {
alert(snippets); // your array in jquery
});
});
});
这篇关于通过jquery发送PHP数组的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文