为什么';jQuery dialog()方法是否中断JavaScript处理?

为什么';jQuery dialog()方法是否中断JavaScript处理?,jquery,dialog,Jquery,Dialog,在继续处理ajax调用之前,我的代码不会等待用户与jQuery对话框交互。为什么它的行为不像JavaScript确认或警报,需要按下按钮才能继续执行客户端脚本 // droppable: Associate droppable to each account type panel (any element on the page having a CSS class of RoleJar), // and in the drop event of droppable invok

在继续处理ajax调用之前,我的代码不会等待用户与jQuery对话框交互。为什么它的行为不像JavaScript确认或警报,需要按下按钮才能继续执行客户端脚本

// droppable: Associate droppable to each account type panel (any element on the page having a CSS class of RoleJar), 
        // and in the drop event of droppable invoke JQuery's ajax function so that it calls the server side page method DropUserIntoRole.
        $('.RoleJar').droppable({
            drop: function (e, ui) {
                var userID = $('#' + draggedObject.id).children('input:hidden')[0].value;

                var accountType = $('#' + this.id).children('input:hidden')[0].value;
                var usersInRole = $('#' + this.id).find('.NamesInRole');

                var userInRole = false;
                for (var i = 0; i < usersInRole.length; i++) {
                    if (usersInRole.children('input:hidden')[i].value == userID) {
                        userInRole = true;
                    }
                }

                var confirmed = false;
                var canEdit = 'false';

                if (userInRole) {
                    alert(userID + ' is already in the ' + accountType + ' Account Type role');

                    confirmDialog = false;
                }
                else {
                    confirmed = confirm('Move ' + userID + ' to the ' + accountType + ' Account Type role?');
                }

                if (confirmed) {
                    $get('" + lblConfirm.ClientID + @"').innerText = 'Grant ' + userID + ' edit privileges?';

                    $('.HiddenPanel').dialog({
                        autoOpen: true,
                        draggable: false,
                        modal: true,
                        resizable: false,
                        title: 'Edit Privileges',
                        buttons: [
                        {
                            text: 'Yes',
                            click: function() {
                                canEdit = 'true';
                                $(this).dialog('close');
                            }
                        },
                        {
                            text: 'No',
                            click: function() {
                                canEdit = 'false';
                                $(this).dialog('close');
                            }
                        }]
                    });
//Why does the dialog invocation above not prevent the below ajax function from being invoked only once user clicks Yes or No?

                    $.ajax({
                        url: currentPage + '/DropUserIntoRole',
                        type: 'POST',
                        dataType: 'json',
                        contentType: 'application/json; charset=utf-8',
                        data: '{ userID: \'' + userID + '\', accountType: \'' + accountType + '\', canEdit: \'' + canEdit + '\' }',
                        success: function (result) {
                            var results = result.d.split(',');
                            alert(results[0] + ' ' + results[1] + ' has been added to the ' + results[2] + ' Account Type');
                            window.location = results[3];
                        },
                        failure: function (result) {
                            alert(result.d);
                        }
                    });
                }
                else {
                    confirmDialog = false;
                }

                droppedToAccountType = true;
                priorAccountType = accountType;
            }
        }).addClass('CornerArcs');
//droppable:将droppable关联到每个帐户类型面板(页面上任何CSS类为RoleJar的元素),
//在droppable的drop事件中,调用JQuery的ajax函数,以便调用服务器端页面方法DropUserIntoRole。
$('.RoleJar')。可拖放({
drop:函数(e、ui){
var userID=$('#'+draggedObject.id).children('input:hidden')[0].value;
var accountType=$('#'+this.id).children('input:hidden')[0].value;
var usersInRole=$('#'+this.id).find('.NamesInRole');
var userInRole=false;
for(var i=0;i
“为什么它的行为不像JavaScript确认或警报?”简短回答-因为它是一个div,而不是确认或警报。将ajax调用放入对话框的按钮单击回调中。感谢您的快速回复。像这样?$('.HiddenPanel').dialog({…close:function(event,ui){$.ajax({url:currentPage+'/dropuserintoole',type:'POST',dataType:'json',contentType:'application/json;charset=utf-8',数据:'{userID:\''+userID+'\',accountType:\'+accountType+'\',canEdit:\'+canEdit+'}',成功:函数(结果){var results=result.d.split(',');alert(results[0]+'+results[1]+'已添加到'+results[2]+'帐户类型');window.location=results[3];},},});},我通过在'No'按钮和'Yes'按钮的click:function()部分运行ajax函数来实现它。谢谢!