English 中文(简体)
How to give Ajax call in modal dialog box
原标题:

I am using modal dialog box from jQuery UI. I want to make a Ajax call to display the content in my dialog box.

$(function(){
    $( #myLink ).live("click", function(){
        $( #lbContent ).dialog( open );
        var url= $(this).attr("href");
        $( div#lbContent ).empty();
        $( div#lbContent ).load(url);
        return false;
    });

    $( #lbContent ).dialog({
        stack:true,
        bgiframe: true,
        autoOpen: false,
        height:500,
        width:700,
        modal: true,
        resizable:true
    });
});

Now, when I click on the link it displays the content in the modal dialog box as expected.

But when I close that dialog box and again click on the same link then that dialog box is not opening. I tried to give alerts in between.

When I refresh the page and click the link then it works as expected.

问题回答

Thank you Peter for editing my initial comment. However, after further investigation to this I have found Shruti s problem to be a true problem for dynamic content. I have even went as far as duplicating jitter s link.

The problem is dynamic content that also uses jQuery files. If I use an URL that goes to the server and requests data from a database using a Cold Fusion page I get the same results as Shruti, it works the first time but not subsequent accesses. If I use a simple HTML page that displays an image on in the dialog it will work ever time.

I removed the jQuery functions from the dynamic content page and it works every time. So there is issues with jQuery if it is also used in the url that is being loaded.

++++++++++++++++++++++++++++++++++++++++++++++

Ok after afew minutes tinkering with this....

If the dynamic page uses the same jQuery files that the main page uses then don t load those files within the dynamic script. That is, the main page is the only page that should load the jQuery files not the dynamic pages that you are trying to load in an element on "the main page". The draw back to this is that the dynamic page in a stand-alone environment won t work because you are not calling jQuery UI.

This is kind of weird because because I can show and hide a standard div tag with dynamic content without modifying anything. But when I want to use the dialog functions in jQuery everything breaks. hmmm!! Still a very valuable library of JavaScript routines --- just need to tweak it a little. That s software.

Can t reproduce your problem. Consider adding a condensed sample consisting of javascript + html code which reproduces the problem consistently.

Also add which browser you use. And what if any errors are shown in your error console.

Check http://jsbin.com/opigo for a working sample based on your code.

And http://jsbin.com/opigo/edit to check the code pieces

Just a word for those developing for systems still using IE 7.0.

$( #lbContent ).dialog({
    stack:true,
    bgiframe: true,
    autoOpen: false,
    height:500,
    width:700,
    modal: true,
    resizable:true,

The last comma in the dialog parameter list will cause the code not to work for IE 7.0.





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签