Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 网格堆栈序列化函数未返回_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 网格堆栈序列化函数未返回

Javascript 网格堆栈序列化函数未返回,javascript,jquery,ajax,Javascript,Jquery,Ajax,我目前正在尝试序列化网格堆栈容器中的所有网格,我可以看到元素属性中包含的值,但是它似乎不希望正确返回对象。当我执行ajax POST请求时,小部件数据没有被分配,因为我的函数返回未定义 window.onbeforeunload = function (e) { //store grid into a variable to be manipulated this.grid = $('.grid-stack').data('gridstack');

我目前正在尝试序列化网格堆栈容器中的所有网格,我可以看到元素属性中包含的值,但是它似乎不希望正确返回对象。当我执行ajax POST请求时,小部件数据没有被分配,因为我的函数返回未定义

window.onbeforeunload = function (e) {
        //store grid into a variable to be manipulated
        this.grid = $('.grid-stack').data('gridstack');

        //we create a saveGrid method to save attributes to the database
        this.save_grid = function () {
            this.serialized_data = _.map($('.grid-stack > .grid-stack-item:visible'), function (el) {
                el = $(el);
                var gridID = el.find('.grid-stack-item-content.ui-draggable-handle').first().attr('id');
                var node = el.data('_gridstack_node');
                return {
                    id: gridID,
                    x: node.x,
                    y: node.y,
                    width: node.width,
                    height: node.height
                };
            }, this);
        };

        $.ajax({
            url: 'Dashboard/EditWidgets/',
            type: 'POST',
            data: {
                widget: this.save_grid
            },
            success: function (dataset) {
            },
            failure: function (xhr, error) {
                console.log(xhr)
                console.log(error)
            },
            cache: false
        })
    };

我会看看你的服务器日志。我认为您发送的是函数本身,而不是结果。换句话说,您缺少括号:
widget:this.save_grid()
刚刚尝试了您的建议,但似乎不起作用,我尝试了将返回设置为变量,但仍然返回为未定义