php - How to make ajax GET request using the filename
Get the solution ↓↓↓I am working on a code where I am trying get the data from a mysql table using a filename through ajax GET request. The table "SAMPLE" contains img_name and x_value. I tried the following code:
index.php:
var full = document.getElementById("img01").src;
var file = full.replace(/^.*[\\\/]/, '');
$.ajax({
type:'GET',
url: 'getfile.php',
data:{
'file':file,
'xvalue':xvalue,
},
success: function(data){
console.log(x);
}
})
getfile.php:
<?php
$db = mysqli_connect('localhost', 'root', '', 'project_focus');
$imagefile=$_GET['file'];
$xvalue=$_GET['xvalue'];
$updatename = "SELECT x_value FROM sample WHERE image_name='$imagefile'";
mysqli_query($db,$updatename);
?>
In the above code, I tried to get the x_value from the table by using the filename in the variable "file" in index.php. But when I tried to print in the console it produces an error 'Uncaught ReferenceError: xvalue is not defined'. The expected result I would like to get x_value from the table using the filename that is in the variable "var file" .
I think I made some mistake with the Get request. Can someone help me to solve this problem
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: a non-numeric value encountered in
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.