简体   繁体   English

Javascript对话框无法打开

[英]Javascript dialog box won't open

I've got a jqGrid that when a user edits a row, they need to click a button to apply the changes. 我有一个jqGrid,当用户编辑一行时,他们需要单击一个按钮以应用更改。 This button should create a dialog box, which should trigger an ajax call with the option selected. 此按钮应创建一个对话框,该对话框应在选中选项的情况下触发ajax调用。

However, the dialog box never opens. 但是,对话框永远不会打开。 Firebug will stop at breakpoints within the function that creates it, but never does what it's supposed to. Firebug会在创建它的函数中的断点处停止,但从不执行应有的功能。

function confirm_dialog(rowData){
    $("#dialog").dialog({
        modal:true,
        buttons: {
            "Yes": function(){
                ajax_call(rowData, "yes");
                $(this).dialog("close");
            },
            "No": function(){
                ajax_call(rowData, "no");
                $(this).dialog("close");
            },
            "Cancel": function(){
                $(this).dialog("close");
            }
        }
    });
}

function ajax_call(rowData, option){
    $.ajax({
        url: '{{django_base}}',
        data: {'data':rowData, 'option':option},
        type: 'POST',
        error: function(){
            window.alert("There was an error!");
        },
        success: function(){
            window.alert("Changes made successfully!");
        }
    });
}

$(function(){
    //...
    baseGrid = new BaseGrid("#the-jqGrid", opts);
    //...setting grid format
    baseGrid.addButton("edit",
        { caption:'Confirm Changes', onClickButton:confirm_dialog() });
}

I've placed a breakpoint at the beginning of confirm_dialog and ajax_call. 我在confirm_dialog和ajax_call的开头放置了一个断点。 It will hit the confirm_dialog break during page load, but not when the button is clicked. 在页面加载期间,它将到达confirm_dialog中断,但是在单击按钮时不会。 The break in ajax_call is never reached. 永远不会达到ajax_call的中断。

If is this your production code, then you missed a comma: 如果这是您的生产代码,那么您错过了一个逗号:

function ajax_call(rowData, option){
$.ajax({
    url: '{{django_base}}',
    data: {'data':rowData, 'option':option},
    type: 'POST',
    error: function(){
        window.alert("There was an error!");
    }, **<-------missed comma**
    success: function(){
        window.alert("Changes made successfully!");
    }
});
}

EDIT I made a fiddle http://jsfiddle.net/94cfma4m/ I think everything is OK with the code itself, maybe the rowData source is invalid? 编辑我做了一个小提琴http://jsfiddle.net/94cfma4m/我认为代码本身一切正常,也许rowData源无效?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM