javascript - 我如何在脚本中分配 php 定义常量值

标签 javascript php ajax url concatenation

这基本上是一个ajax响应,我想从我存储在常量中的配置文件分配位置

define(BASE_URL, "http://example.net/lc-latest/");
$website =  BASE_URL ;

这是我的示例页面代码脚本:

if (response["success"] == true) {
    $("#showMessage").html(response['message']);
    location = "/lc-latest/gdpi.php?jobid="+response["id"]

    /* I want to re write this link as `$website` so that if I changed
    the project location it should not disturb.*/

    location = "<?php BASE_URL ?>gdpi.php?jobid="+response["id"] //can i write like this in script of ajax response.?
    window.open(location);
  }

最佳答案

你可以像这样将BASE_URL变量保存在html中

<body base_url="<?php echo BASE_URL ?>">

然后在你的 ajax 响应中使用 jQuery 读取它,就像这样

location = $('body').attr('base_url') + "gdpi.php?jobid="+response["id"]

关于javascript - 我如何在脚本中分配 php 定义常量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40380394/

相关文章:

php - 使用 $_GET 和 $_POST

javascript - 多次ajax调用后页面加载图像

ajax - 通过 Ajax 将下拉选择的值(列表)作为参数传递给 Controller

javascript - 在 emscripten 中更改默认命名空间 'Module'

javascript - Jvector 将国家名称更改为数据库名称?

php - Amazon S3 上传错误 PermanentRedirectException

php - docker compose 的最佳部署策略(LAMP 堆栈)

ruby-on-rails - 闪光[:notice] not working when using AJAX in Rails

javascript - Chrome 文件阅读器

javascript - 在 LODASH 中,断言对象或数组中存在键的最佳方法是什么?