开发者

problem in jQuery popup and ajax

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/cmdbac开发者_StackOverflowktohomepagetop_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");
    }


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜