1

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
user3210341
  • 77
  • 1
  • 2
  • 14

1 Answers1

0

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);
});
prabeen giri
  • 803
  • 7
  • 18
  • thanks for your reply, but it still does not work after i add the forward slash. The error is: GET http://wego/get_search_id.php – user3210341 Jan 25 '14 at 10:07