doudi2005
2018-06-21 05:05
浏览 104

我的模态对话框表单没有使用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;
            }

图片转代码服务由CSDN问答提供 功能建议

在模态对话框中,提交值不会传入我的控制器

  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('添加/更新数据时出错'); 
 提交表单按钮时没有响应错误添加/更新数据显示 
 
 
   public function book_update()
 {
 $ markid = $ this-&gt; input-&gt; post('markid'); 
 $ subcode = $ this-&gt; input-&gt; post('subcode  '); 
 echo $ markid; 
 echo $ subcode; 
} 
   
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doulupian8725 2018-06-21 05:14
    已采纳

    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;
    }
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题