2016-09-19 21 views
-1

它尝试在php中使用Ajax。 是编写代码,并在年底发VAR“ID”到PHP文件:将var发送到javascript文件中

xmlhttp.open("GET", "details.php?q="+Id,true); 

存在的代码没有问题,details.php运行,但details.php给我这个错误:注意:未定义指数:身份证在C:\ wamp64 \ WWW \ ADV3 \上线先进\前端\网络\ details.php 2

在这里它是我在details.php行Seconde系列:

<?php 
$q = $_GET['Id']; 

什么问题是什么?我发送Id很好。

+2

您正在传递查询字符串为q。所以使用$ q = $ _GET ['q'];而不是Id。 –

回答

2

你得到一个错误,因为你发送的查询字符串参数是q,而不是Id

xmlhttp.open("GET", "details.php?q="+Id,true); 
           ^^ 

所以你的PHP应该是

$q = $_GET['q']; 
-1

哪个浏览器是你吗?无论如何;你可以使用JQuery让你的生活变得更容易。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> 
<script type="text/javascript"> 
    (function($) { 
     $(document).ready(function(){ 
      $.ajax({ 
       url  : "details.php", 
       type : "GET", 
       data : {"Id" : Id }, 
       success: function (data, textStatus, jqXHR){ 
       }, 

       error: function (jqXHR, textStatus, errorThrown) { 
        console.log('The following error occurred: ' + textStatus, errorThrown); 
       } 
      }); 
     }); 
    })(jQuery); 
</script> 
相关问题