在javascript变量中添加php定义变量
Add php define variable in javascript variable
我有一个php变量,需要将其传递到javascript函数中的链接中
//In the config
<?php
define('THE_VAR', 'test');
?>
//On the page
<?php
$the_var = THE_VAR;
?>
<script>
(function()){
link = "test.site"+<?php echo json_encode($the_var); ?>+"/testing.js"
})();
</script>
我需要javascript函数中的链接来阅读。
test.site/test/testing.js
代替:link = "test.site"+<?php echo json_encode($the_var); ?>+"/testing.js"
使用:link = "test.site/<?= $the_var; ?>/testing.js";
使用Ajax将数据从php传递到javascript。
http://www.w3schools.com/ajax/ajax_php.asp
相关文章:
- 将PHP变量传递给jQuery时遇到问题
- 通过javascript重定向html传递php变量
- 如何在php变量中嵌入JQuery代码
- 在javascript函数中使用php变量
- 将地理编码结果转换为php变量以发布到mysql数据库
- JavaScript,PHP-用JavaScript将多个数据库记录发送到变量或表
- 如何将变量php传递给javascript
- 显示动态变量(php和javascript)的总数
- 传递变量PHP、Javascript location.reload和HTML输入
- 需要将变量 php 的值传递给 javascript,但我不能
- 将变量从 .html 传递到太大而无法容纳在 URL 中的变量.php
- 如何在函数中传递javascript中的变量php
- 在Jquery中插入变量PHP
- 选择正确的变量 php/javascript
- 将HTML存储在变量PHP中,然后回显它
- 将变量PHP Smarty传递给Javascript
- 传递HTML表单post数据到不同的文件/网页javascript变量(php)
- 问题与传递变量(php, sql, jquery拖拽)
- 设置PHP中的javascaript变量(PHP在javascript中)
- 将变量php问题化为代码jquery