开发者

Linking javascript BASEDIR

开发者 https://www.devze.com 2022-12-28 01:00 出处:网络
So continue from this: Linking how PHP/HTML Please check the answer i accepted, and i used the \"BASEDIR\" solution zneak came with.

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){}});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号