这基本上是一个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/