drupal 7 module js ajax get file path

1.1k views Asked by At

i have one module: wego, and i want to use ajax in wego.js which is located in wego/js/wego.js. The ajax needs send get request to get_data.php which is located in wego/get_data.php. My server setting is test.drupal.com. Here is my code:

jQuery(function() {
    var $basepath = Drupal.settings.basePath;
    //alert($basepath); outputs '/'
    jQuery.get($basepath+'wego/get_search_id.php',function(data){
      alert(data);
    });
});

and i add this js file in wego.module:

function wego_init() {
  drupal_add_js(drupal_get_path('module', 'wego') . '/js/wego.js');
}

Does anyone know why the get_search_id.php can not be found? The error message is:

http://test.drupal.com/wego/get_search_id.php can not be found
1

There are 1 answers

1
prabeen giri On

Its because you missed the forward slash after Drupal.settings.basePath in jQuery.get

It should be likes this

jQuery.get($basepath + '/wego/get_search_id.php',function(data){
   alert(data);
});