通过PHP数组的jQuery [英] pass php array to jquery
本文介绍了通过PHP数组的jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以请给我一个简单的例子应该如何才能从PHP传递数组jQuery的jQuery的$就语法的样子。
在服务器端我有:
$ a =阵列(1,2,3,4,5);
回声json_en code($ A);
所以,我希望得到这个js和有:
js_array = [1,2,3,4,5];
我真的AP preciate任何帮助,因为我一直想有一段时间了,并没有运气。
感谢您!
解决方案
$。阿贾克斯({
方法:GET,//或POST
网址:'yourfile.php',
数据类型:JSON,
数据:{} //把数据通过GET / POST发送到这个对象,如果有必要
成功:函数(响应){
//响应阵列
}
});
Can someone please give me a simple example how should jquery $.ajax syntax look like in order to pass array from php to jquery.
On server side I have:
$a=array(1,2,3,4,5);
echo json_encode($a);
So, I'd like get this to js and have:
js_array=[1,2,3,4,5];
I'd really appreciate any help, cause I've been trying for some time now and no luck.
Thank you!
解决方案
$.ajax({
method: 'GET', // or POST
url: 'yourfile.php',
dataType: 'json',
data: {}, // put data to be sent via GET/POST into this object if necessary
success: function(response) {
// response is your array
}
});
这篇关于通过PHP数组的jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文