Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/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
Javascript 如何声明PHP变量并将其传递到AJAX url?_Javascript_Php_Ajax - Fatal编程技术网

Javascript 如何声明PHP变量并将其传递到AJAX url?

Javascript 如何声明PHP变量并将其传递到AJAX url?,javascript,php,ajax,Javascript,Php,Ajax,当我调用/comment.php时,它返回我请求的数据。其中post_id是固定的 /comment.php "ajax": { "url": "http://localhost/fb-callback.php?post_id=12345_67890", "type" : "GET", "dataSrc": function (response) { // console.log(response);

当我调用
/comment.php
时,它返回我请求的数据。其中post_id是固定的

/comment.php

 "ajax":
{
 "url": "http://localhost/fb-callback.php?post_id=12345_67890",
   "type" : "GET",
"dataSrc":  function (response) { 
                // console.log(response);
                            if(response.whaterver == 0){
                               //DO YOUR THING HERE
                            }
                            //return back the response
                            return response; 
                        },
我想在这里声明一个php变量,而不是固定id(12345_67890), 类似这样的东西::-

<?php
$uid = $_GET['uid'];
?>

 "ajax":
{
 "url": "http://localhost/fb-callback.php?post_id="+"&uid",
"type" : "GET",
 ................

“ajax”:
{
“url”:”http://localhost/fb-callback.php?post_id=“+”&uid“,
“类型”:“获取”,
................
因此,当我调用url
/comment.php?uid=12345_67890**
时,它将返回结果。但它似乎不是这样工作的。 我该怎么做,或者有其他方法打这个电话吗


以下是完整的代码::

您可以
在ajax url上回送它。试试这个

 <?php
  $uid = $_GET['uid'];
?>

 "ajax":
{
 "url": "http://localhost/fb-callback.php?post_id=<?php echo $uid; ?>",
 "type" : "GET",
 ................

“ajax”:
{
“url”:”http://localhost/fb-callback.php?post_id=",
“类型”:“获取”,
................
试试这个

<?php
$uid = $_GET['uid'];
?>
var uid = <?php echo $uid; ?>;
 "ajax":
{
 "url": "http://localhost/fb-callback.php?post_id="+uid,
"type" : "GET",
 ................

变量uid=;
“ajax”:
{
“url”:”http://localhost/fb-callback.php?post_id=“+uid,
“类型”:“获取”,
................

“url”:http://localhost/fb-callback.php?post_id=“,
另请参见此处:谢谢,这真的帮了我很大的忙……感谢:)这是一种糟糕的编码实践。