jQuery code
$.ajax({
url: "far-area_m.php",
type: "POST",
dataType: 'json',
data: values ,
success: function (response) {
alert("sdfds");
// you will get response from your php page (what you echo or print)
},
error: function(jqXHR, textStatus, errorThrown) {
alert(textStatus);
console.log(textStatus, errorThrown);
}
});
far-area_m.php
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname='lateral';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$len = $_REQUEST["len"];
$bre = $_REQUEST["bre"];
$wid = $_REQUEST["wid"];
$sql = mysqli_query(
$conn,
"INSERT INTO `far_input` (`length`, `breadth`, `width`)
VALUES
('".$len."', '".$bre."', '".$wid."')
");
$data = array(
'len' => $len,
'bre' => $bre,
'wid' => $wid
);
echo json_encode($data);
?>
always Ajax response is printing error.But if I comment the insert statement in far-area_m.php I am getting response. Please tell me what is wrong with the code. on sucess of jquery I am not getting any response its throwing error.