Skip to content Skip to sidebar Skip to footer

How To Insert Into Mysql Table Using Ajax?

I want to insert data into table using ajax so data will insert without reload of page. This code insert data into table very well but code also reload the page. But I want insert

Solution 1:

try this add this to form onsubmit = "return submitform();"

 function submitform(){
    var comment = $("#comment").val();
    var alertid = $("#alertid").val();
    $.ajax({
        type: "POST",
        //url: "ana.php",
        data:{cmt:comment,alert_id:alertid}
    }).done(function( result ) {
        $("#msg").html( result );
    });
    return false;
  }

Solution 2:

return false from your event handler function.

onsubmit="submitform(); return false;">

Consider moving to modern methods of event binding.


Solution 3:

You have to create a php file that insert into your table the posted data and call it with ajax like that :

$.ajax({
url: "/file.php",
type: "POST",
cache: false,
dataType: "json",
data: postValue,
success: function(results) {
    bootbox.alert(results.message, function() {
        bootbox.setIcons(null);
        window.location.reload();
    });
},
error: function(results) {
    bootbox.alert(results.message, function() {
        bootbox.setIcons(null);
    });
}

});


Post a Comment for "How To Insert Into Mysql Table Using Ajax?"