Hi,
I've been trying for a day on this one but still no luck.
I'm tryng to submit or post (?) a single input field value into a MySQL database using Ajax,
so the webpage is not reloaded.
The php database storage code is working fine (I've tested it).
The problem is with the HTML Form code and/or the JQuery.Ajax code. I can't get the single Form Input value (which shows up correctly in my debugger) into the database using my current Ajax code.
The JQuery Serialize website states...
"No submit button value is serialized since the form was not submitted using a button."
However, I'm including the serialize in the onclick event to bypass this??

Can anyone please tell me the correct way of doing this?
Thank you.
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
$('#petnamesubmit').click(function(){
$.ajax({
url: phpdb.php,
type:'POST',
data: $(this).serialize(),
success: function(msg){
alert("Data has been submitted to the Database");
}
});
}
);
UPDATE: .....
I'm now trying a plain button click event for my HTML/Ajax combo; rather than the above "INPUT" method:
Code:
<form id="petform" >
Enter your pets name: <input id="petinput" type="text" name="petname" />
<button id="petnamesubmit" type="button"> Submit to Database </>
</form>
Code:
$('#petnamesubmit').click(function(){
var petnamevalue = $("input#petinput").val();
$.ajax({
url: phpdb.php,
type:'POST',
data: petnamevalue,
success: function(msg){
alert("Data has been submitted to the Database");
}
});
}
);
But still no luck ??
Thanks.