ajaxSubmit 与 SimpleModal 结合使用不会触发成功委托

发布于 2024-10-16 16:49:46 字数 1277 浏览 1 评论 0原文

使用以下代码,我尝试在 ajaxSubmit 之后执行一些操作,但成功委托永远不会被触发。 ajaxSubmit 代码到达 asp.net 控制器,该控制器成功处理带有 JSON 结果的请求。模型表单包含一个执行 AjaxSubmitAndClose 的按钮。

function ShowModal(rendercontainerid, modalcontainerid, url) {
        if (url == '')
            return;
        $.get(url, function(data) {
            $(rendercontainerid).html(data);
            $(rendercontainerid).modal({
                close: false,
                containerId: modalcontainerid
            });
        });
    }

    function AjaxSubmitAndClose(formid) {
        var options = { 
                        beforeSubmit:  showRequest,
                        success: showResponse,
                        dataType: 'json'
                        };


        $(form).ajaxSubmit(options);
    }

    function showRequest(formData, jqForm, options) 
    { 
        $('#formSub').html('We really appreciate your feedback!');
        var queryString = $.param(formData); 
        alert('About to submit: \n\n' + queryString); 
        return true; 
    }

    function showResponse(responseText, statusText) 
    {
        alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
            '\n\nThe output div should have already been updated with the responseText.'); 
    }

With the following code I'm trying to execute some actions after the ajaxSubmit, but the success delegate is never fired. The ajaxSubmit code reaches the asp.net controller who succesfully handles the request with an JSON result. The model form contains an button who executes the AjaxSubmitAndClose.

function ShowModal(rendercontainerid, modalcontainerid, url) {
        if (url == '')
            return;
        $.get(url, function(data) {
            $(rendercontainerid).html(data);
            $(rendercontainerid).modal({
                close: false,
                containerId: modalcontainerid
            });
        });
    }

    function AjaxSubmitAndClose(formid) {
        var options = { 
                        beforeSubmit:  showRequest,
                        success: showResponse,
                        dataType: 'json'
                        };


        $(form).ajaxSubmit(options);
    }

    function showRequest(formData, jqForm, options) 
    { 
        $('#formSub').html('We really appreciate your feedback!');
        var queryString = $.param(formData); 
        alert('About to submit: \n\n' + queryString); 
        return true; 
    }

    function showResponse(responseText, statusText) 
    {
        alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
            '\n\nThe output div should have already been updated with the responseText.'); 
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

喜爱皱眉﹌ 2024-10-23 16:49:46

如果您使用 ASP.NET,我相信您需要使用模式的 appendTo:'form' 选项:

$(rendercontainerid).modal({
    appendTo: 'form',
    close: false,
    containerId: modalcontainerid,
    // snip
});

If you are using ASP.NET, I believe you need to use the appendTo:'form' option for the modal:

$(rendercontainerid).modal({
    appendTo: 'form',
    close: false,
    containerId: modalcontainerid,
    // snip
});
ヤ经典坏疍 2024-10-23 16:49:46

在调查这种奇怪的行为后,我发现了一个开放的 bug
然后我在露天拍摄了一张照片,并从选项中删除了数据类型
对象,令人惊讶的是一切又恢复正常了。

After investigating this strange behavior I found an open bug.
Then I did a shot in the open and I removed dataType from the Options
object and surprisingly everything was working again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文