Code:
<form id="petform" action="/" method="post">
Enter your pets name: <input id="petinput" type="text" name="petname" />
<input id="petnamesubmit" type="submit" value="Submit to Database" />
</form>
Code:
// PHP MySQL: Post PetName to MySQL Database using AJAX
$(function() {
$('#petform').submit(function(){
$.ajax({
url: phpdb.php,
type:'POST',
data: $(this).serialize(),
success: function(msg){
alert("Data has been submitted to the Database");
}
});
});
});
you were getting the first error becuase you were trying to serialize the button itself becuase you binded the function to.
i put your code in a document ready section and binded directlky to the forms submit event. give this a shot