I got two submit buttons in a form. One that deletes the post, and one to edit it.
I want to display a fancybox with either the edit-form or a message saying that the user deleted the post. It's all decided by which button was pushed, with a "if(isset)"-sentence in edit.php. However I can't figure out how to get the value of the button within the serializeArray.. I tried with .click(function() instead, but that didn't send anything to the fancybox..
$("#form").bind("submit", function() {
$.ajax({
开发者_开发百科 type : "POST",
cache : false,
url : "edit.php",
data : $(this).serializeArray(),
success: function(data) {
$.fancybox(data);
}
});
return false;
});
The form looks like this:
<form method='post' action='' id="form">
<input type='submit' value='Edit' name='edit' />
<input type='submit' value='Delete' name='delete' onClick="return slett('<?php echo $oppgave->name; ?>')"/>
<input name='oppgaveID' type='hidden' value='<?php echo $oppgave->id; ?>' />
</form>
I would really appreciate it if someone could help me! Thanks in advance!
From the jQuery docs for serialize()
:
Only "successful controls" are serialized to the string. No submit button value is serialized since the form was not submitted using a button. For a form element's value to be included in the serialized string, the element must have a name attribute. Data from file select elements is not serialized.
The rules for a "successful control" are defined here:
http://www.w3.org/TR/html401/interact/forms.html#h-17.13.2
Also check out this Stack Overflow solution from Nick Craver.
精彩评论