In my local machine, I am trying to save data from a json to my mysql database, I am using Wampserver.
In my html page (saveInfo.php), I have this jquery code:
<script type="text/javascript">
var jsObj = {"user_id":5, "login":"hsm"};
var jsonobj = JSON.stringify(jsObj);
$.ajax({
type: "POST",
url: "json_handler.php",
data: { 'jsonobj':jsonobj },
success: function(){
alert('success');
window.location = "http://localhost/quranMapping/php/json_handler.php";
}
});
</script>
In the other side, I have my server-side php code (json_handler.php
) like that:
<?php
$input = file_get_contents('php://input');
$input = $_POST['jsonobj'];
$result = json_decode($input);
echo $result->user_id;
?>
But when I run that code, I get this error: