4

Hi I'm using jquery ui dialog and trying to submit form using ajax and display its response. Till form dialog and ajax request its working fine but don't know how to display its response in same dialog. Any suggestion going to help me.

1
  • 2
    Some code might shed some light... Commented Nov 23, 2010 at 12:13

2 Answers 2

5

Suppose you have the following markup

<div id="__DialogPanel" style="display:none" title=""></div>

With this code you setup the dialog

$("#__DialogPanel").dialog({
    autoOpen: false,
    resizable: false,
    position: 'center',
    stack: true,
    height: 'auto',
    width: 'auto',
    modal: true
});

With this code you show the dialog and include the results of an ajax call

$.ajax({
    type: "get",
    dataType: "html",
    url: 'some/url',
    data: {},
    success: function(response) {
        $("#__DialogPanel").empty().html(response).dialog('open');
    }
});

With this code you submit the form in the dialog and then close it if everything is ok or display again the form if has errors

$.ajax({
    type: 'post',
    dataType: 'html',
    url: '/someother/url',
    async: false,
    data: $("#myform").serialize(),
    success: function (response, status, xml) {
        //Check for error here
        if (error) {
            $("#myform").parent().html('').html(response);
        }
        else {
            $("#__DialogPanel").dialog('close');
        }
    }
});

Hope it helps!

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

Comments

0

I guess you open your dialog like this:

$.post('xyz.htm', function(data) { $('#mydialog .mytarget').html(data).slideDown(); });

The trick is using the callback function (which gets as parameter the response), and dumping the response into your desired element.

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.