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();           

            });
        }
    });
}

代码绑定:

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

1 回答 1

0

看起来您没有捕获来自 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!
}

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

祝你好运!

于 2010-05-26T15:33:11.077 回答