来自PHP的jQuery ajax数据数组 [英] jquery ajax data array from php
本文介绍了来自PHP的jQuery ajax数据数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是我的代码,因此您可以看到我正在尝试执行的操作,显然这是行不通的:
heres my code so you see what i'm trying to do, which obviously isn't working:
$('#selector').change(function() {
if ($(this).val().length > 0)
{
$.ajax({
type: "POST",
url: "ajax.php",
data: "id="+$(this).val(),
success: function(data){
if (data != 'error')
{
$('#main_url').val(data[2]);
$('#main_url_title').val(data[3]);
}
}
});
}
});
我设置了一个警报(数据);弹出的就是"Array".所以现在我的2个字段中都填充了"r"和"a" ...正确的方法是什么?
i set up an alert(data); and all it pops up with is "Array". so now my 2 fields are being populated with "r" and "a"...what is the correct way of doing this?
推荐答案
我认为您可以在json数据中编码php数组,然后在jQuery中使用json
I think you may encode php array in json data, and then use json with jquery
在ajax.php中添加类似echo json_encode($your_php_array)
Add in ajax.php something like echo json_encode($your_php_array)
这篇关于来自PHP的jQuery ajax数据数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文