Related Thread: jQuery Ajax returns the whole page
The above thread is related, and this seems to be a somewhat common problem, but the answer in that thread doesn't exactly help in my situation.
When an image on my page is clicked, a jQuery function is called, and in that function is an Ajax declaration:
//click an image
$(".img_div").click(function() {
//get integer stored in alt attribute and pass to variable
var altCheck = $(this).find('.modal_img').attr('alt');
//get MySQL data
$.ajax({
//php file to grab data
url: "get.php",
type: "post",
datatype: "json",
//pass above variable to php file
data:{ ajaxid: altCheck },
success: function(response){
//log data to console
console.log(response);
},
error: function(){
console.log("test");
}
});
I'm trying to log the received data into the console purely as a test right now, but I'm getting the entire index.html page logged into the console instead.
A connection has been made to the database and stored in variable $db
prior to any image clicks.
Here is my get.php file:
<?php
//variable from jQuery
$value = filter_var($_REQUEST["ajaxid"], FILTER_SANITIZE_STRING);
$value = mysqli_real_escape_string($value);
//variable passed to SQL statement
$sql = $conn->prepare("SELECT FROM table WHERE screeningId = ?");
$sql->bind_param("s",$value);
//Get data
$result = mysqli_query($db, $sql);
while ($row = mysqli_fetch_array($result)){
//output data
echo $row['url'];
}
?>