jQuery .dialog() + .post() problem
I have a form on modal dialog that need to be filled up and on pressing "Save" save results into database. I use following code to open form which is jQuery-ui dialog and jQuery .post() method. I don't need to show anything when form is closed开发者_运维百科 and processed.
$('#cdialog').dialog({
autoOpen: false,
modal: true,
buttons: {
"Save": function() {
$.post('process.php', $("#cform").serialize());
$(this).dialog('close');
},
Cancel: function() {
$(this).dialog('close');
}
}
});
$('#cdialog').dialog('open');
This is code in process.php
$data = (object)array(
'map' => $_POST['map'],
'type' => $_POST['type'],
'name' => $_POST['name']
);
Concepts::save($data);
I checked with alert($("#testform").serialize())
in "Save" function that parameters are actually being passed. Checked with Apache log that POST request is being sent. But it is still not working. If I just run php file passing all parametes in array without trying to get $_POST variables, data is saved. I don't understand why it is not working from dialog...
I believe you are having a timing issue. Please change your code from
"Save": function() {
$.post('process.php', $("#cform").serialize());
$(this).dialog('close');
}
to reflect the following
"Save": function() {
$.post('process.php', $("#cform").serialize(), function () {
$('#cdialog').dialog('close');
});
}
精彩评论