【问题标题】:CodeIgniter AJAX InsertionCodeIgniter AJAX 插入
【发布时间】:2015-08-08 04:53:20
【问题描述】:

我想使用 codeigniter 创建照片标签我指的是这个网站 (http://techlister.com/php/simple-photo-tagging-with-php-and-jquery/1176/) 数据插入不正常。如果您能帮我解决这个问题,那将是一个很大的帮助。

这是我的代码

控制器

public function addImageData()
    {
        $this->load->model('test_model');
        $this->test_model->insert_imageData();

    }

型号

public function insert_imageData()
{
        $data = array(
            'id' => $this->input->post('pic_id'),
            'name' => $this->input->post('name'),
            'pic_x' => $this->input->post('pic_x'),
            'pic_y' => $this->input->post('pic_y')
        );

        $insert = $this->db->insert('image_tag', $data);
        return $insert;
}

查看-代码段

 // Save button click - save tagsfe
        $( document ).on( 'click',  '#tagit #btnsave', function(){
            name = $('#tagname').val();
            var img = $('#imgtag').find( 'img' );
            var id = $( img ).attr( 'id' );
            $.ajax({
                type: "POST",
                url: "<?php echo base_url().'Treatments_Controller/addImageData'; ?>",
                data: "pic_id=" + id + "&name=" + name + "&pic_x=" + mouseX + "&pic_y=" + mouseY + "&type=insert",
                cache: true,
                success: function(data){
                    //viewtag( id );
                    $('#tagit').fadeOut();
                }
            });

        });

【问题讨论】:

    标签: php jquery ajax codeigniter codeigniter-2


    【解决方案1】:

    像这样更改你的网址

           url: "<?php echo base_url();?>Treatments_Controller/addImageData",
    

    【讨论】:

    • 请提供您的答案的详细信息。只有代码是不够的。
    • @Sergey Denisov 仍然无法正常工作。在站点演示中,当我们单击图片时,它会显示一个输入字段以输入文本,当我们保存它时,数据会保存在数据库中,文本框会淡出。这里我做了上面提供的所有更改,但该文本框不会淡出并且数据没有保存在数据库中。相反,如果我只是在另一个选项卡中输入了我在 ajax 函数中提供的 url,则空值保存在数据库中(意味着控制器和模型部分正在工作。我不知道 ajax 部分有问题)希望你有我的问题。
    【解决方案2】:
    In view page,
    if you are having a button:
    <a href="javascript:void(0)" onclick="insert()"><button> Insert </button>
    <script>
    function insert(){
         name = $('#tagname').val();
         var img = $('#imgtag').find( 'img' );
         var id = $( img ).attr( 'id' );
         $.ajax({
               type: "POST",
               url: "<?php echo base_url();?>+'Treatments_Controller/addImageData'",
                        data: {"pic_id=" + id + "&name=" + name + "&pic_x=" + mouseX + "&pic_y=" + mouseY + "&type=insert"},
                        success: function(data){
                            //viewtag( id );
                            $('#tagit').fadeOut();
                            alert(data);
                        }
                    });
    
                });
    

    你也可以用ajax做:

               data: $("#form_id").serialize(),
    

    还在控制器中添加echo "inserted";。为了回应

    【讨论】:

      猜你喜欢
      • 2020-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-11
      • 1970-01-01
      • 2023-03-20
      • 2012-10-06
      • 1970-01-01
      相关资源
      最近更新 更多