Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用文件名发出ajax GET请求_Php_Ajax - Fatal编程技术网

Php 如何使用文件名发出ajax GET请求

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:{

我正在编写一段代码,试图通过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:{
     '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_值