jQuery 弹出窗口和 ajax 中的问题

发布于 2024-09-03 09:25:30 字数 2288 浏览 2 评论 0原文

当我进行 ajax 调用时遇到问题,然后我的弹出窗口停止工作。 当我们点击弹出窗口的“确定”按钮时,我想调用ajax。 预先感谢

这是我的代码:


<div id='container'>
    <div id='content'>
        <div id='confirm-dialog'>
       <asp:Button ID="cmdBackToHomePageTop" runat="server" Text="<<  Back to Home Page" Width="160px" OnClick="cmdBackToHomePageTop_Click"/>

        </div>

        <!-- modal content -->
        <div id='confirm'>
            <div class='header'><span>Test Conformation Title</span></div>
            <div class='message'></div>
            <div class='buttons'>
                <div class='no simplemodal-close'>Cancle</div><div id='ok' class='yes'>Ok</div>
            </div>
        </div>

    </div>

</div>

jQuery 文件

    jQuery(function ($) {
    $('[id$=button],[id$=cmdBackToHomePageTop]').click(function (e) {
        e.preventDefault();

        // example of calling the confirm function
        // you must use a callback function to perform the "yes" action
        confirm("hello friends?", function () { 


            $.ajax({
                    type: "post",
                    url: "./default2.aspx/cmdbacktohomepagetop_click"
                   )};      
        });
    });
});

function confirm(message, callback) {
    $('#confirm').modal({
        //closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
        position: ["20%",],
        overlayId: 'confirm-overlay',
        containerId: 'confirm-container', 
        onShow: function (dialog) {
            $('.message', dialog.data[0]).append(message);

            // if the user clicks "yes"
            $('#ok', dialog.data[0]).click(function () {
                // call the callback

                if ($.isFunction(callback)) {
                    callback.apply();       
                }
                // close the dialog
                $.modal.close();           

            });
        }
    });
}

codebhind:

protected void cmdBackToHomePageTop_Click(object sender, EventArgs e)
    {
        Response.Write("called --- cmdBackToHomePageTop_Click");
    }

i am having problem when i do the ajax call then my popup stop working.
i want to call ajax when we click on "ok" button of popup.
thanks in advance

here is my code:


<div id='container'>
    <div id='content'>
        <div id='confirm-dialog'>
       <asp:Button ID="cmdBackToHomePageTop" runat="server" Text="<<  Back to Home Page" Width="160px" OnClick="cmdBackToHomePageTop_Click"/>

        </div>

        <!-- modal content -->
        <div id='confirm'>
            <div class='header'><span>Test Conformation Title</span></div>
            <div class='message'></div>
            <div class='buttons'>
                <div class='no simplemodal-close'>Cancle</div><div id='ok' class='yes'>Ok</div>
            </div>
        </div>

    </div>

</div>

jQuery file

    jQuery(function ($) {
    $('[id$=button],[id$=cmdBackToHomePageTop]').click(function (e) {
        e.preventDefault();

        // example of calling the confirm function
        // you must use a callback function to perform the "yes" action
        confirm("hello friends?", function () { 


            $.ajax({
                    type: "post",
                    url: "./default2.aspx/cmdbacktohomepagetop_click"
                   )};      
        });
    });
});

function confirm(message, callback) {
    $('#confirm').modal({
        //closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
        position: ["20%",],
        overlayId: 'confirm-overlay',
        containerId: 'confirm-container', 
        onShow: function (dialog) {
            $('.message', dialog.data[0]).append(message);

            // if the user clicks "yes"
            $('#ok', dialog.data[0]).click(function () {
                // call the callback

                if ($.isFunction(callback)) {
                    callback.apply();       
                }
                // close the dialog
                $.modal.close();           

            });
        }
    });
}

codebhind:

protected void cmdBackToHomePageTop_Click(object sender, EventArgs e)
    {
        Response.Write("called --- cmdBackToHomePageTop_Click");
    }

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

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

发布评论

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

评论(1

初相遇 2024-09-10 09:25:30

您似乎没有捕获 Ajax 调用的响应。看起来您已经执行了一个回调(当用户在确认中单击“确定”时),但您仍然需要向 Ajax 请求本身添加另一个回调。否则,请求会很好地发生,您只是没有对结果做任何事情。

通常,您需要通过 $.ajax( 的 successerror 和/或 complete 属性为此提供回调函数。 ..);

例如,

$.ajax({
    type: "post",
    url: "./default2.aspx/cmdbacktohomepagetop_click",
    data: 'xml',
    success: mySuccessHandler,
    error: function() {alert('Bummer, an error occurred')}
)};
function mySuccessHandler(data) {
    // process the response!
}

您可以参考此页面获取更多文档和示例。特别是有关最终将传递到各种回调中的参数的更多信息。我举的例子只是为了展示一些可能性。

祝你好运!

It looks like you're not capturing the response from the Ajax call. It looks like you're already doing one callback (when the user clicks OK in the confirmation) but you still need to add another to the Ajax request itself. Otherwise, the request is happening just fine, you're just not doing anything with the results.

Usually, you will want to supply your callback function to this via the success, error, and/or complete properties of $.ajax(...);

For example,

$.ajax({
    type: "post",
    url: "./default2.aspx/cmdbacktohomepagetop_click",
    data: 'xml',
    success: mySuccessHandler,
    error: function() {alert('Bummer, an error occurred')}
)};
function mySuccessHandler(data) {
    // process the response!
}

You can refer to this page for more documentation and examples. Especially for more information on the parameters that will end up getting passed into your various callbacks. The example I gave is just to show some possibilities.

best of luck!

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