Skip to main content
added 101 characters in body
Source Link
enchance
  • 2.1k
  • 5
  • 39
  • 50

Thanks to everyone who's commented (especially @jcisio)! Based on all your answers, I was able to come up with thisthe THEMEPATH global variable which works perfectly:stores the complete path to the theme by using drupal_add_js().

drupal_add_js( array( 'themepath' => base_path() . path_to_theme() ), 'setting' );

Which you can then reference in your .js file as

var THEMEPATH; //a global variable
$(function(){
    THEMEPATH = Drupal.settings.themepath; //assign the variable
})

//THEMEPATH has to be aassigned globalon variablepage load and not before or else it won't work

So in the end, you simply use it in jQuery as: THEMEPATH + '/code/test-ajax.php'. I'm surprised Drupal doesn't have this by default.

Thanks to everyone who's commented! Based on all your answers I was able to come up with this which works perfectly:

drupal_add_js( array( 'themepath' => base_path() . path_to_theme() ), 'setting' );

Which you can then reference in your .js file as

var THEMEPATH; //global variable
$(function(){
    THEMEPATH = Drupal.settings.themepath;
})

//THEMEPATH has to be a global variable or else it won't work

So in the end, you simply use it in jQuery as: THEMEPATH + '/code/test-ajax.php'

Thanks to everyone who's commented (especially @jcisio)! Based on all your answers, I was able to come up with the THEMEPATH global variable which stores the complete path to the theme by using drupal_add_js().

drupal_add_js( array( 'themepath' => base_path() . path_to_theme() ), 'setting' );

Which you can then reference in your .js file as

var THEMEPATH; //a global variable
$(function(){
    THEMEPATH = Drupal.settings.themepath; //assign the variable
})

//THEMEPATH has to be assigned on page load and not before or else it won't work

So in the end, you simply use it in jQuery as: THEMEPATH + '/code/test-ajax.php'. I'm surprised Drupal doesn't have this by default.

added 86 characters in body
Source Link
enchance
  • 2.1k
  • 5
  • 39
  • 50

Thanks to everyone who's commented! Based on all your answers I was able to come up with this which works perfectly:

drupal_add_js( array( 'themepath' => base_path() . path_to_theme() ), 'setting' );

Which you can then reference in your .js file as

var THEMEPATH; //global variable
$(function(){
    THEMEPATH = Drupal.settings.themepath;
})

//THEMEPATH has to be a global variable or else it won't work

So in the end, you simply use it in jQuery as: THEMEPATH + '/code/test-ajax.php'

Thanks to everyone who's commented! Based on all your answers I was able to come up with this which works perfectly:

drupal_add_js( array( 'themepath' => base_path() . path_to_theme() ), 'setting' );

Which you can then reference in your .js file as

var THEMEPATH; //global variable
$(function(){
    THEMEPATH = Drupal.settings.themepath;
})

//THEMEPATH has to be a global variable or else it won't work

Thanks to everyone who's commented! Based on all your answers I was able to come up with this which works perfectly:

drupal_add_js( array( 'themepath' => base_path() . path_to_theme() ), 'setting' );

Which you can then reference in your .js file as

var THEMEPATH; //global variable
$(function(){
    THEMEPATH = Drupal.settings.themepath;
})

//THEMEPATH has to be a global variable or else it won't work

So in the end, you simply use it in jQuery as: THEMEPATH + '/code/test-ajax.php'

Source Link
enchance
  • 2.1k
  • 5
  • 39
  • 50

Thanks to everyone who's commented! Based on all your answers I was able to come up with this which works perfectly:

drupal_add_js( array( 'themepath' => base_path() . path_to_theme() ), 'setting' );

Which you can then reference in your .js file as

var THEMEPATH; //global variable
$(function(){
    THEMEPATH = Drupal.settings.themepath;
})

//THEMEPATH has to be a global variable or else it won't work