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 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥200 uniapp长期运行卡死问题解决
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
    • ¥15 乘性高斯噪声在深度学习网络中的应用
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决