我有一个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