【发布时间】:2016-05-14 07:30:28
【问题描述】:
如何使用 ajax 传递数组? 我的代码在视图中:
$(document).ready(function(){
$('#btn-send').click(function(){
var value = {
'name': $('#name').val(),
'phone': $('#phone').val(),
'mail': $('#mail').val(),
};
$.ajax({
type: 'POST',
url: '<?php echo site_url('customer_add/test'); ?>',
data: value,
success: function(resp){
$('#error').html(resp);
}
});
});
});
我的测试方法:
public function test5(){
$data = $this->input->post["value"];
$name = $data['name'];
echo $name;
}
在 params 中 - 在 inspect 元素中 - 有数据,但作为响应,没有什么可以返回。 怎么了? 提前致谢。
【问题讨论】:
-
试试这个
success : function(data) { //alert("ok"); }, error: function(er){ alert("There is some error"); console.log(er.responseText); } -
您在 ajax 中请求函数测试,并且在代码中您向我们展示了服务器脚本中的函数 test5 ???
标签: arrays ajax codeigniter