Php 如何使用文件名发出ajax GET请求
我正在编写一段代码,试图通过ajax get请求使用文件名从mysql表中获取数据。表“SAMPLE”包含img_名称和x_值。我尝试了以下代码: index.php:Php 如何使用文件名发出ajax GET请求,php,ajax,Php,Ajax,我正在编写一段代码,试图通过ajax get请求使用文件名从mysql表中获取数据。表“SAMPLE”包含img_名称和x_值。我尝试了以下代码: index.php: var full = document.getElementById("img01").src; var file = full.replace(/^.*[\\\/]/, ''); $.ajax({ type:'GET', url: 'getfile.php', data:{
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);
?>
从何处获取x
值,即:'xvalue':x
?@Swati我想从表中获取x值。我明白了这里的x
是什么'xvalue':x,
作为xvalue
的值传递,它必须为null。删除它并查看您从后端获取的值。另外,你能显示你得到的全部错误吗?@Swati我已经编辑了代码。@Swati我想做什么->使用变量“file”中的文件名,我试图检索表中该文件名的x_值