View Single Post
Old 10-23-2012, 04:19 AM   PM User | #4
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,306
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
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
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote