0

I am trying to post data from my form to a jquery dialog that loads external content.

I am serializing the form data which works (appears in the url) but the dialog won't open:

      $("#wavajax button").click(function() {
  $.post({url: 'player/index.php', data: $("#wavajax").serialize(), 
         success: function (data) {

                     $("#recordingdialog").load("player/index.php", [], function(){
               $("#recordingdialog").dialog("open");

                 }
  });
  return false;
});

What am I doing wrong, am I going about it the right way???

3
  • Are you creating the dialog before this? Also unsure why you're doing a POST then a GET of the same URL? Commented Jun 5, 2010 at 10:07
  • I am trying to post the data to player/index.php and have that page open up in a dialog with the posted data within Commented Jun 5, 2010 at 10:10
  • the ui dialog should open kind regardless if #recordingdialog is a div which is placed in your markup and you including all dialog ui dependencies. Commented Jun 5, 2010 at 10:11

3 Answers 3

4

I think this is what you're after:

$("#wavajax button").click(function() {
  $.post('player/index.php', $("#wavajax").serialize(), function (data) {
       $("#recordingdialog").html(data).dialog("open");
  });
  return false;
});

You're already getting the HTML content back from the POST (or at least I would think this is the case), so just put that response in the #recordingdialog using .html() and then make the dialog call. If you're not previously creating a dialog with options, then just .dialog() will suffice, .dialog('open') is intended for when you created the dialog earlier with various options and want to now open it, like this:

$("#recordingdialog").dialog({
  //other options, width, height, etc...
  autoOpen: false
});

You can find a full list of these options here

Sign up to request clarification or add additional context in comments.

3 Comments

This works nicely. But when I close the dialog and click to open it again nothing happens any ideas why o masterful nick
@user that shouldn't be the case...is there anything else messing with that #recordingdialog element?
Yep I had a header included in the top of the player/index.php file. removed it and everything is fine. YOU THE MAN!!!!
0

Its maybe a better idea to first display the dialog and load the content.

$('#recordingdialog').dialog('destroy'); // just in case
$('#recordingdialog').dialog({
   position: 'center',
   // some more options
   open:  function(e, ui){
        $.post('player/index.php', data: $("#wavajax").serialize(),function (data){   
              $("#recordingdialog").html(data);   
        });
   }
});

within your click handler.

UI Dialog Doc

3 Comments

This approach leaves a blank dialog waiting for the content to load, then will flash when it does, I don't believe this is an approach that should be used....also check your $.post() call, it's not valid :)
I guess this approach is way better than just letting nothing happen after pressing the button. It's maybe a good idea to insert some kind of loading gif into the dialog on opening.
Your current answer throws a javascript syntax error, so it's not better yet ;)
0

Ok I have it working with this:

      $("#recordingdialog").dialog({
  //other options, width, height, etc...
     modal: true,
      bgiframe: true,
      autoOpen: false,
      height: 550,
      width: 550,
      draggable: true,
      resizeable: true,
      title: "Play Recording",});


$("#wavajax button").click(function() {
  $.post('player/index.php', $("#wavajax").serialize(), function (data) {
       $("#recordingdialog").html(data).dialog("open");
  });
  return false;
});

Thanks Nick! But have one issue. When I close the dialog and click on the button to open it again nothing happens why not???

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.