Linking javascript BASEDIR
So continue from this: Linking how PHP/HTML
Please check the answer i accepted, and i used the "BASEDIR" solution zneak came with.
Now i ran onto another problem.. in my ajax_framework.js i have:
开发者_C百科$.ajax({url: "session.php", success: function(data){
how should i include BASEDIR onto this? i was thinking something about:
$.ajax({url: "'.BASEDIR.'session.php", success: function(data){
but this isnt PHP, so i think you cant? no? any help or maybe another method to come around this?
Javascript also supports string concatenation:
$.ajax({url: baseDir + "/session.php", success: function(data) {
You will need to set the baseDir
Javascript variable in Top.php
:
<script language="text/javascript">
var baseDir = "<?php echo BASEDIR; ?>";
</script>
Why not just set a BASEDIR variable into your template set by your php code ?
Update your php code like this :
<?php define('BASEDIR', '..'); ?>
// in top.php
<?php if(!defined('BASEDIR')) define('BASEDIR', '.'); ?>
<link rel="stylesheet" type="text/css" href="<?php echo BASEDIR; ?>/style.css"/ >
<script type="text/javascript">
var BASEDIR = "<?php echo BASEDIR; ?>";
</script>
Then concatenate with +
$.ajax({url: BASEDIR + 'session.php", success: function(data){}});
精彩评论