Karem
Karem

Reputation: 18103

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:

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

Upvotes: 0

Views: 3414

Answers (2)

Boris Guéry
Boris Guéry

Reputation: 47585

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

Upvotes: 2

SLaks
SLaks

Reputation: 887245

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>

Upvotes: 2

Related Questions