0

Edited to add the solution suggested by @alistair-laing.) After reading this post reply by @jek, I could make multiple links on my page that would pass an id variable through the URL so that the content of the dialog could be loaded in on the fly. However, I really want this to be a modal dialog: (edited to include the fix; nb: the original script was in the post linked to above, all I did was break it)

$(function (){
  $('a.ajax').click(function() {
   var url = this.href;
   var dialog = $('<div style="display:none"></div>')
   .appendTo('body')
  // load remote content
   dialog.load(
     url, 
     {},
     function (responseText, textStatus, XMLHttpRequest) {
        dialog.dialog({ 
        modal: true,
        width: 500
      });
    }
   );
   //prevent the browser to follow the link
   return false;
 });
});
Community
  • 1
  • 1
Blll P
  • 118
  • 1
  • 9
  • quiet a few things. Try move the content from your first .dialog into your second .dialog which you call as part of the the .load callback. What youare doing is creating dialog then injecting content into it only to call it again. You could also remove the the autoOpen so that the dialog opens with the content. – Alistair Laing Sep 16 '11 at 11:36
  • No problem. Seeing as you are a new user, Can you flag my comment as a great comment and make your question as answered. – Alistair Laing Sep 16 '11 at 14:08
  • I searched for how to do that, but I don't know how... This is lame but, how do I to that? – Blll P Sep 17 '11 at 12:30
  • @Alistair, why don't you repost your comment as an answer, making it easier for Bill to accept the answer, as well as the later-comers to spot it? – William Niu Sep 17 '11 at 23:44

1 Answers1

0

quiet a few things. Try move the content from your first .dialog into your second .dialog which you call as part of the the .load callback. What youare doing is creating dialog then injecting content into it only to call it again. You could also remove the the autoOpen so that the dialog opens with the content.

Alistair Laing
  • 983
  • 1
  • 7
  • 18