dtu72460 2015-05-24 00:18
浏览 29

使用JS + Ajax和CodeIgniter发布序列化字符串

I have a ul list of items that can be sorted using JQueryUI sortable. Currently, I am able to drag and rearrange the ul items with no problem, and I am generating a console.debug message like I'd like, however, it doesnt seem to be posting the data to my controller's method which handles the data, and sends it to my model to update the SQL DB.

Basically, the admin will be shown a list of active pages on the site, and will allow them to rearrange the order of the navigation links on the front of the site.

$(document).ready(function() {
    $('#sortable').sortable(
        {
            axis: 'y',
            update: function (event, ui) {
                var data = $('#sortable').sortable('serialize');

                var getUrl = window.location;
                var baseUrl = getUrl .protocol + "//" + getUrl.host + "/" 
                    + getUrl.pathname.split('/')[1];

                console.debug(data);
                // POST to server using $.post or $.ajax
                $.ajax({
                    data: data,
                    type: 'POST',
                    url: baseUrl + '/admin/pages/update/'
                });
            }
        }
    );
});

Dragging an element in the list will generate a debug message, id[]=2&id[]=1&id[]=3&id[]=4&id[]=7&id[]=6&id[]=5&id[]=8&id[]=9&id[]=10 which is set up perfect for what I'm attempting to do

The above SHOULD be posting to the following method of my Pages controller. I'm currently using a little hacked together code for my own learning, attempting to make it send a debug message. If I access /pages/update directly it will show the debug message, before redirecting me to /pages/index.

public function update()
{
    echo '<script type="text/javascript">';
    echo 'console.debug("Update Page Accessed:");';
    echo '</script>';
    redirect('admin/pages/index', 'refresh');
}

If I can get the debug message to show up after I drag an element, I'll be able to sort myself out from there.

Edit I just took a look at my JS console, and it seems that I've been hiding all my errors for Jquery.

POST http://localhost/~/admin/pages/update/ 500 (Internal Server Error)

Taking a look at my resources, it appears to be a CodeIgniter error being generated,

An Error Was Encountered. The action you have requested is not allowed.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大