douqiang7976 2014-04-03 18:42
浏览 47

使用jQuery序列化与CodeIgniter函数

I need some help with jQuery and serialize.

I am not very good with javascript so this might be such a simple problem that i am doing wrong but I am working on an application within codeigniter and one of the features is a drag and drop system which allows you to re-order the images and then save the order and update the order/weight in a MySQL database. Now, I can drag and drop the images fine, press the button which calls that save_order function and the success alert shows but nothing actually happens and i'm clueless as to why. Like I said, i am completely new to javascript/jQuery so it is probably something so simple. Any help would be greatly appreciated.

This is my javascript:

$(function() {
    $( "#imgs" ).sortable();
});

function save_order(){   
    $.ajax({
        url: "<?php echo site_url('admin/gallery/change_order'); ?>",
        type: 'POST',
        data: $("#imgs").sortable("serialize"),
        success: function(msg){
            alert('Success');
        },
        error: function (XHR, status, response) {
            alert('An error occurred!');
        }
    });             
}

and this is gallery/change_order

public function change_order()
{
    $items = $this->input->post('car');

    foreach($items as $key => $value)
    {
        $data = array('weight' => $value);

        $this->db->update('images', $data, array('id' => $key));
    }
}
  • 写回答

1条回答 默认 最新

  • duanhuiqing9528 2014-04-03 18:52
    关注

    I think you have an error in the way you call 'serialize'. It should be something like:

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

    Keep in mind that 'serialize' will work only on form elements.

    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况