English 中文(简体)
AJAX 数据字符串中的 PHP 变量
原标题:PHP variable inside AJAX data string

我得到uncault referenceError: 当我在下面运行 AJAX 调用时, bierta( 或不管 URL var 是哪个 ) 都没有定义 。 我如何才能解决这个问题?

$.ajax({
  type: "GET",
  async: false,
  url: "get-single-marker.php",
  data: "slug="+<?php echo $_GET[ gt ]; ?>,
  dataType: "json",
  success: function(res) {
    data = res;
  }
});
最佳回答

尝试

data: "slug=<?php echo $_GET[ gt ]; ?>,

data: { slug:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

问题回答

你想要的东西 比如:

data: "slug="+<?php echo json_encode($_GET[ gt ]); ?>,

data: "slug=<?php echo $_GET[ gt ]; ?>",

或 grab the gt from the query using JavaScript.

View source to see why your version doesn t w或k.

无论您使用何种方法, 您都需要确保您正确验证/ 跳出输入 。 $_ GET 是不信任的东西 。

您在此为元素指定一个变量, 这就是为什么它给了您一个错误 。

尝试跟随代码 。

data: "slug=<?php echo $_GET[ gt ]; ?>",

这项工作应该有效

希望这行得通

data: { slug : <?php echo $_GET[ gt ]; ?> }  ,

不需要引用





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...