views:

105

answers:

2

Hello. So continue from this: http://stackoverflow.com/questions/2715295/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:

$.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?

+1  A: 

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>
SLaks
Cant get it to work.. the BASEDIR is PHP define();
Karem
What gets rendered? (View source)
SLaks
now it works with the variable..! thank you too bad i cant accept both answers because the both works well and are the correct answers.. hope its ok Boris Guerey
Karem
+2  A: 

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){}});
Boris Guéry