I have a AJAX call that looks like this and I have included the tag as well:
<script>
$.post("../processor/get_notifications.php",
{
id: <?php echo $_SESSION["id"]; ?>
},
function(data, status){
console.log("Data: " + data + "\nStatus: " + status);
});
</script>
And the .php file looks like this:
<?php
if(isset($_POST["id"])){
require '../includes/backbone.php'; //It contains the server information
$connection = mysqli_connect($server_name, $database_username, $database_password, $database_name);
$sql = "SELECT user_json FROM users WHERE id = " . $_POST["id"] . "";
$result = mysqli_query($connection, $sql);
echo $result;
}
So, I am trying to pass the user_json stored in the database to the page from where the AJAX call is done. But, It shows an internal server error. I guessed that the error was caused as the variable $result may be an object. And when I tried to check if the type of the variable was object using echo gettype($result);
, it showed object in the console. So, I tried to change the object to string using three methods out of which none worked:
$result = "'" . $result . "'"; //which I was sure wouldn't work
$result = (string)$result;
$result =json_decode($result); //which didn't make sense
. So, How am I supposed to get the object in the page to do something like:document.write(object["about"]);
or so on?