如何在ajax函数中执行Jquery可排序取消?

如何在ajax函数中执行Jquery可排序取消?,jquery,Jquery,我使用jquerysortable来拖动表行,一旦拖动完成,我将使用ajax调用来更新数据库的状态。 如果ajax调用失败,如何取消排序操作 在我使用的ajax调用中 $( this ).sortable( "cancel" ); 我在控制台里得到了什么 VM107 jquery.min.js:2 Uncaught Error: cannot call methods on sortable prior to initialization; attempted to call method '

我使用jquerysortable来拖动表行,一旦拖动完成,我将使用ajax调用来更新数据库的状态。 如果ajax调用失败,如何取消排序操作

在我使用的ajax调用中

$( this ).sortable( "cancel" );
我在控制台里得到了什么

VM107 jquery.min.js:2 Uncaught Error: cannot call methods on sortable prior to initialization; attempted to call method 'cancel'
这是我的密码

$(document).ready(function()
{
        var fixHelperModified = function(e, tr)
        {
                var $originals = tr.children();
                var $helper = tr.clone();
                $helper.children().each(function(index)
                {
                        $(this).width($originals.eq(index).width())
                });
                return $helper;
        };
        $("#sort tbody").sortable(
        {
                helper: fixHelperModified,
                delay: 175,
                start: function(e, ui)
                {
                        var pac_id = ui.item.attr('pac_id');
                        $(this).attr('data-pac_id', pac_id);
                        $(this).attr('data-previndex', ui.item.index());
                },
                stop: function(e, ui)
                {
                        var newIndex = ui.item.index() + 1;
                        var oldIndex = parseInt($(this).attr('data-previndex')) + 1;
                        var pac_id = $(this).attr('data-pac_id');
                        var inputjson = {
                                'pac_id': pac_id,
                                'old_position': oldIndex,
                                'new_position': newIndex
                        };
                        var reqested_data = JSON.stringify(inputjson);
                        var ajaxres = '';
                        $.ajax(
                        {

                               success: function(response)
                                {
                                     if(2<3)
                                     {
                                        $( this ).sortable( "cancel" );
                                     }

                                },
                                 error: function(jqXHR, exception)
                                {
                                $( this ).sortable( "cancel" );
        alert('please try again');
                                }


                        }).done(function() {});
                        $(this).removeAttr('data-previndex');
                        $(this).removeAttr('data-pac_id');
                },
        }).disableSelection();
});
$(文档).ready(函数()
{
var FIXHELPERMODIFED=函数(e,tr)
{
var$originals=tr.children();
var$helper=tr.clone();
$helper.children().each(函数(索引)
{
$(this).width($originals.eq(index.width())
});
返回$helper;
};
$(“#排序体”)。可排序(
{
helper:fixHelperModified,
延误:175,
开始:功能(e、ui)
{
var pac_id=ui.item.attr('pac_id');
$(this.attr('data-pac_id',pac_id));
$(this.attr('data-previndex',ui.item.index());
},
停止:功能(e、ui)
{
var newIndex=ui.item.index()+1;
var oldIndex=parseInt($(this).attr('data-previndex'))+1;
var pac_id=$(this.attr('data-pac_id');
var inputjson={
“pac_id”:pac_id,
“旧位置”:旧索引,
“新建位置”:新建索引
};
var requested_data=JSON.stringify(inputjson);
var ajaxres=“”;
$.ajax(
{
成功:功能(响应)
{

如果(2取消初始化可排序插件的元素的可排序

在本文中指的是ajax调用的成功函数,而不是排序表的停止函数

 $("#sort tbody").sortable("cancel");

演示:

取消初始化可排序插件的元素的可排序

在本文中指的是ajax调用的成功函数,而不是排序表的停止函数

 $("#sort tbody").sortable("cancel");
演示:

$(this)元素不能在ajax内部调用。因此,分配一些变量并调用它

以下

 $.ajax({
$( this ).sortable( "cancel" );
进入

var elem = $(this);
$.ajax({
elem.sortable( "cancel" );
以下

 $.ajax({
$( this ).sortable( "cancel" );
进入

var elem = $(this);
$.ajax({
elem.sortable( "cancel" );
$(this)元素不能在ajax内部调用。因此,分配一些变量并调用它

以下

 $.ajax({
$( this ).sortable( "cancel" );
进入

var elem = $(this);
$.ajax({
elem.sortable( "cancel" );
以下

 $.ajax({
$( this ).sortable( "cancel" );
进入

var elem = $(this);
$.ajax({
elem.sortable( "cancel" );

@未知欢迎:-)@未知欢迎:-)