I am trying to send a JSON object via ajax to the same page. While running my code, the ajax function does seem to send the data, as I can see on the response, that the $id in the PHP code, is changed to 200, but I am unable to display it on the webpage. I have included the jquery.js file (I'm not sure if I need to add another js library or not). I tried looking at a lot of stackoverflow answers but was unable to solve my problem. Any help would be appreciated.
PHP Code:
<?php
if(isset($_POST['area_id'])){
$id = $_POST['area_id'];
echo "Area ID: ".$id;
} else {
echo "test";
}
?>
JQuery AJAX
var dat = {area_id: 200, title: 'title'};
$.ajax({
type:"POST",
data: dat,
success:function(res){
alert(res);
}
});