将php全局变量传递给ajax.success()

时间:2019-04-22 09:36:26

标签: javascript ajax

我有一些ajax代码:

$.ajax({
  url: "/ajax/createOrder.php",
  type: "POST",
  cache: false,
  data: {
    "nameSelf": nameSelf,
    "phoneSelf": phoneSelf,
    "email": email,
    "delivery": delivery
  },
  dataType: "html",
  success: function(data) {
    -- -- -- -- -- -- > $("#orderConfirmationDescription").html("<?php $userOrderId ?>");
  }
});

我应该如何将全局$userOrderId传递到元素中?

1 个答案:

答案 0 :(得分:1)

在PHP中使用echo,并删除双引号。

$("#orderConfirmationDescription").html(<?php echo $userOrderId; ?>);