HTML --
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
Field: <span id="test"></span>
<form id="form" method="post">
<input type="submit" name="submit" value="Submit" />
<input type="submit" name="submit" value="Don't Click" />
</form>
<script>
/* attach a submit handler to the form */
$("#form").submit(function(event) {
/* stop form from submitting normally */
event.preventDefault();
/* set all the vars you want to post on here */
var parameters = {
'submit': $('input[name="submit"]').val()
};
$.ajax({
url: 'php/test.php',
method:'POST',
data: parameters,
success: function(msg) {
$('#test').append(msg);
}
})
});
PHP --
<?php
$submit = $_POST['submit'];
if($submit === "Submit"){
echo 'Success!';
} else if($submit === "Don't Click") {
echo 'You Effed Up!';
}
?>
When I run the Ajax call, it always displays Success in the Field: area. Why is that? Should it not be getting the value of whichever submit button was clicked?