提交后关闭添加对话框

时间:2016-01-21 14:12:42

标签: jquery jqgrid

我使用jqrrid 4.6.0

  
      
  • @license jqGrid 4.6.0 - jQuery Grid
  •   
  • 版权所有(c)2008,Tony Tomov,tony @ trirand.com
  •   

事情是我添加新记录后,对话框没有关闭。

$(gridSelector).jqGrid('navGrid', pagerSelector,
                {
                    //navbar options
                    edit: true,
                    editicon: 'ace-icon fa fa-pencil blue',
                    add: true,
                    addicon: 'ace-icon fa fa-plus-circle purple',
                    del: true,
                    delicon: 'ace-icon fa fa-trash-o red',
                    search: true,
                    searchicon: 'ace-icon fa fa-search orange',
                    refresh: true,
                    refreshicon: 'ace-icon fa fa-refresh green',
                    view: true,
                    viewicon: 'ace-icon fa fa-search-plus grey'
                },
                {
                    //edit record form
                    //closeAfterEdit: true,
                    //width: 700,
                    recreateForm: true,
                    mtype: 'PUT',
                    onclickSubmit: function (params, postdata) {
                        params.url = API_URL;
                    },
                    beforeShowForm: function (e) {
                        var form = $(e[0]);
                        form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />');
                        styleEditForm(form);
                    }
                },
                {
                    //new record form
                    //width: 700,
                    closeAfterAdd: true,
                    recreateForm: true,
                    viewPagerButtons: false,
                    mtype: 'POST',
                    onclickSubmit: function (params, postdata) {
                        params.url = API_URL + 'PostVendor';
                    },
                    afterSubmit: function (response, postdata) {
                        var userKey = JSON.parse(response.responseText).UserKey;
                        alert("The password you created for the new vendor is\n\n" + userKey);
                    },
                    beforeShowForm: function (e) {
                        var form = $(e[0]);
                        form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar')
                            .wrapInner('<div class="widget-header" />');
                        styleEditForm(form);
                    }
                }

但我closeAfterAdd: true部分POST

1 个答案:

答案 0 :(得分:1)

您遇到问题的原因很简单,但很难找到。你包含了afterSubmit,你以错误的方式实现了它。回调函数必须返回至少包含一个元素的数组。通常,回调返回

[true]

这意味着jqGrid应该将服务器响应解释为成功。如果分析服务器响应的内容显示请求的服务器端处理失败,则回调afterSubmit应该返回结果,如

[false, "It's <em>Important</em> error on the server side!!!"]

您的代码返回undefined,我认为在调用afterSubmit回调后您将在处理下一个语句时看到异常,因为res[0]将与undefined变量一起使用res

相关问题