Pregunta

I am using $.post() to retrieve content from the database, which I then want to use to manipulate form values. Once this is done I want the jQuery dialog box to open. It is for a very simple "edit event" system I am writing. I just cannot get the dialog box to open within the $.post(), and if I do it outside of the $.post(), the form values return empty.

I understand the concept that it won't work because the script continues to run irrespective if the callback is successful, but is there another way to do this?

My code:

// Edit a banner:
$("input[name='eventEditBtn']").click(function() {
    var eventID = $(this).attr("rel");
    $.post("www/scripts/ajax/getEventInfo.php",{id : eventID},function(data) {
        if(data.success == true) {
            var info = data.info;
            $("input[name='editEventName']").val(info.name);
            $("input[name='editEventDate']").val(info.date);
            $("input[name='editEventTime']").val(info.time);
            $("textarea[name='editEventSummary']").val(info.summary);
            $("textarea[name='editEventDescription']").val(info.description);
            $("#editEventCurrentCategory").html("The current category is: "+info.categoryName);
            $("input[name='editEventVenue']").val(info.venue);
            $("input[name='editEventCost']").val(info.cost);
            $("#editEventCurrentStatus").html("The current status is: "+info.categoryName);
            $("#editEventContainer").dialog({width: 600, title: "EDIT EVENT:"});
        } else {
            $("<div />").dialog("An error has occured retrieving this event information.");
            return false;
        }
    });
    return false;
});
¿Fue útil?

Solución

Maybe because the inputs are being modified before the dialog is being initialized? Try to initialize it before the $.post call like this, for example:

$('#editEventContainer').dialog({
            autoOpen: false,
            width: 600,
            title: "EDIT EVENT:"
});

and then your $.post call opens the dialog using:

$('#editEventContainer').dialog('open');

Remember also to check that the selectors are right.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top