On the click of a button, I want to capture a form’s data and send it to a php page using ajax, json. Now, the alert “hello hello” comes on the click of a button ONLY WHEN I HAVE COMMENTED OUT MY AJAX PORTION.
When i include the ajax portion by un-commenting it, not only do i not get any errors but also my “hello hello” alert doesnt show up.
I find this odd. Why does it happen so?
Here is my ajax:
<script>
$(document).ready(function () {
$("#btn").click( function() {
alert('hello hello');
/* Coomenting starts here
$.ajax({
url: "connection.php",
type: "POST",
data: {
id: $('#id').val(),
name: $('#name').val(),
Address: $('#Address').val()
}
datatype: "json",
success: function (status)
{
if (status.success == false)
{
alert("Failure!");
}
else
{
alert("Success!");
}
}
});
*/
//commenting ends here.
//basically i just commented out the ajax portion
});
});
</script>
You are missing a comma after “data”:
As @dystroy pointed out, since your code can’t compile, this malformed block will potentially prevent other code (such as a simple alert) from firing.