我的模态对话框表单没有使用ajax提交给php中的控制器
问题描述:
In modal dialog form submit value are not passed in to the my controller
function save()
{
var url;
url = "<?php echo site_url('index.php/User/book_update')?>";
$.ajax({
url : url,
type: "POST",
data: $('#form').serialize(),
dataType: "JSON",
success: function(data)
{
$('#modal_form').modal('hide');
},
error: function (jqXHR, textStatus, errorThrown)
{
alert('Error adding / update data');
}
});
}
while submitting form button no response only Error adding / update data shows
public function book_update()
{
$markid= $this->input->post('markid');
$subcode=$this->input->post('subcode');
echo $markid;
echo $subcode;
}
在模态对话框中,提交值不会传入我的控制器 p>
function save()
{
var url;
url =“&lt;?php echo site_url('index.php / User / book_update')?&gt;”;
$ .ajax({
url:url,
type:“POST”,
data:$('#form')。serialize(),
dataType:“JSON”,
success:function(data)
{\ n $('#modal_form')。modal('hide');
},
error:function(jqXHR,textStatus,errorThrown)
{
alert('添加/更新数据时出错');
提交表单按钮时没有响应错误添加/更新数据显示 p>
public function book_update()
{
$ markid = $ this-&gt; input-&gt; post('markid');
$ subcode = $ this-&gt; input-&gt; post('subcode ');
echo $ markid;
echo $ subcode;
}
code> pre>
div>
答
Hope this will help you
Your url
should be like this :
url = "<?php echo site_url('User/book_update')?>";
Instead of this :
url = "<?php echo site_url('index.php/User/book_update')?>";
js
function should be like this :
function save()
{
var url;
url = "<?php echo site_url('User/book_update')?>";
$.ajax({
url : url,
type: "POST",
data: $('#form').serialize(),
dataType: "JSON",
success: function(data)
{
$('#modal_form').modal('hide');
},
error: function (jqXHR, textStatus, errorThrown)
{
alert('Error adding / update data');
}
});
}
Your controller's book_update
method should be like this :
public function book_update()
{
$markid = $this->input->post('markid');
$subcode = $this->input->post('subcode');
$array = array('markid' => $markid);
echo json_encode($array);
exit;
}