我想通过ajax将按钮onclick frome视图的id发送给控制器,但它返回错误:
500内部服务器错误
我的观点:
<a data-toggle="modal"data-target="#Add_Money_to_campaign" ><button onclick="addId('<?php echo $id;?>');"> Add</button></a>
控制器
$id= $this->input->post('dataString');
$this->model->function($id);
脚本:
function addId(id){
var dataString = id
alert(dataString)
$.ajax({
type: "post",
url: "<?php echo base_url('controller/function');?>",
data: {dataString:dataString},
cache: false,
success: function(html){
alert(html);
}
});
}
答案 0 :(得分:0)
我正在更新你的代码
您的观点:
<a data-toggle="modal" data-target="#Add_Money_to_campaign" ><input type="submit" value="Add" onclick="addId(<?php echo $id;?>);" /></a>
你的JS:
function addId(id){
var id = id
alert(id);
$.ajax({
type: "post",
url: "<?php echo base_url('controller/function');?>",
data: {id:id},
cache: false,
async: false,
success: function(result){
console.log(result);
}
});
}
您的功能
$id= $this->input->post('id');
echo $id;
$this->model->function($id);// you might have error over here you need to specify your model_name as my_model