Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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
在post请求中传递jquery.sortable(';serialize';)的结果_Jquery_Jquery Ui_Coffeescript - Fatal编程技术网

在post请求中传递jquery.sortable(';serialize';)的结果

在post请求中传递jquery.sortable(';serialize';)的结果,jquery,jquery-ui,coffeescript,Jquery,Jquery Ui,Coffeescript,所以我知道,$('#table_content').sortable('serialize')返回一个数组,因为我使用console.info对它进行了测试。我想做的是在post请求中使用该表达式的值作为数据,但我希望它的结果作为数据在回调中传递给另一个ajax请求。我想我可以通过将$('#table_content').sortable('serialize')作为.post的数据参数来实现这一点,但当我这样做时,根据firebug,参数是“undefined=undefined” jQuer

所以我知道,
$('#table_content').sortable('serialize')
返回一个数组,因为我使用console.info对它进行了测试。我想做的是在post请求中使用该表达式的值作为数据,但我希望它的结果作为数据在回调中传递给另一个ajax请求。我想我可以通过将
$('#table_content').sortable('serialize')
作为.post的数据参数来实现这一点,但当我这样做时,根据firebug,参数是“undefined=undefined”

jQuery ->
  ids = $('#table_content').sortable('serialize')
  console.info(ids)

  $('#tasks_table').load('/dashboard #tasks_table', null, -> $.post('/tasks/sort', $('#table_content').sortable('serialize'), ->location.reload()))

undefined=undefined

你知道为什么会这样吗?请注意,如果我在
$('#table_content').sortable('serialize')
的位置传递
ids
,则它可以工作,但我只希望在上一个ajax请求运行后返回
$('#table_content').sortable('serialize')
的值。如果我只使用ID,那么它的值不会反映调用
$(“#tasks_table”)后的更改。从您的示例中加载

,加载后似乎会得到以下结构(当然可能不是DIV元素):


对此不确定,但在对加载的内容调用“serialize”方法之前,您可能必须初始化可排序插件

$('#tasks_table').load('/dashboard #tasks_table', null, function() {
    var ids = $('#table_content')
        .sortable() // init first
        .sortable('serialize'); // then call 'serialize'
    $.post('/tasks/sort', ids, function() {
        location.reload()
    });
});

从您的示例来看,似乎在加载后会得到以下结构(当然可能不是DIV元素):


对此不确定,但在对加载的内容调用“serialize”方法之前,您可能必须初始化可排序插件

$('#tasks_table').load('/dashboard #tasks_table', null, function() {
    var ids = $('#table_content')
        .sortable() // init first
        .sortable('serialize'); // then call 'serialize'
    $.post('/tasks/sort', ids, function() {
        location.reload()
    });
});

谢谢!我只需要在回调函数中初始化ids变量。这很有道理。除了location.reload()函数重新加载页面,并且在执行post请求后更改的新数据不会显示外,它现在工作得很好。相反,我必须手动重新加载页面,然后才能反映更改。这对我来说似乎有点奇怪,因为我认为post请求的回调函数只有在post请求成功发出后才会执行。关于这一点有什么想法吗?这是一个成功的回调,所以它被称为成功。您确定发布的数据吗?你确定你在服务器端用它做什么吗?另外,如果以后重新加载整个页面,为什么要使用ajax呢?非常感谢!我只需要在回调函数中初始化ids变量。这很有道理。除了location.reload()函数重新加载页面,并且在执行post请求后更改的新数据不会显示外,它现在工作得很好。相反,我必须手动重新加载页面,然后才能反映更改。这对我来说似乎有点奇怪,因为我认为post请求的回调函数只有在post请求成功发出后才会执行。关于这一点有什么想法吗?这是一个成功的回调,所以它被称为成功。您确定发布的数据吗?你确定你在服务器端用它做什么吗?另外,如果以后重新加载整个页面,为什么要使用ajax?
$('#tasks_table').load('/dashboard #tasks_table', null, function() {
    var ids = $('#table_content')
        .sortable() // init first
        .sortable('serialize'); // then call 'serialize'
    $.post('/tasks/sort', ids, function() {
        location.reload()
    });
});