So my issue is submitting a form via AJAX with jQuery when I submit it to the PHP it doesn't matter what button submits the form when using the jQuery AJAX but when using a form action the form submits and lets me know if the delete or update button was pushed. For example here's the HTML to submit the form
<input type="submit" name="update" value="Update">
<input type="submit" name="delete" value="Delete">
Here's the AJAX Call below.
$(document).ready(function() {
$("#update-form").submit(function () {
$.ajax({
type: "POST",
url: "updateHandler.php",
data: $("#update-form").serialize(),
success: function(data) {
var login = JSON.parse(data);
if (login.success) {
alert(login.message); //Show the ticket was updated!
} else {
alert(login.message);
}
}
});
return false;
});
});
Now here's my PHP code that the AJAX Calls.
<?php
$json_data = array();
if(isset($_POST['delete'])) {
$json_data['message'] = 'Ticket was deleted!';
} else {
$json_data['message'] = 'Ticket was updated!';
}
// Encode response as JSON
echo (json_encode($json_data));
?>
EDIT
After being asked for the console output here's what I got
The "No Button Pushed" if from the code from the answer by adeneo
{"success":true,"message":"No Button Pushed"}
Array
(
[ticket-num] => 6
[technician] => 1
[category] => 1
[email] => [email protected]
[name] => Ned Stark
[country] => Canada
[issue] => I'm Having an issue with Product Y
)
button name='action' value='update'andbutton name='action' value='delete'then you can just evaluate$_POST['action']