【问题标题】:drupal 7 module js ajax get file pathdrupal 7模块js ajax获取文件路径
【发布时间】:2014-01-25 09:28:11
【问题描述】:

我有一个模块:wego,我想在位于 wego/js/wego.js 的 wego.js 中使用 ajax。 ajax 需要向位于 wego/get_data.php 的 get_data.php 发送 get 请求。我的服务器设置是 test.drupal.com。这是我的代码:

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

我在 wego.module 中添加了这个 js 文件:

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

有人知道为什么找不到 get_search_id.php 吗?错误信息是:

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

【问题讨论】:

    标签: ajax drupal-7 drupal-modules drupal-ajax


    【解决方案1】:

    这是因为你错过了 jQuery.get 中 Drupal.settings.basePath 之后的正斜杠

    应该是这样的

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

    【讨论】:

    • 感谢您的回复,但我添加正斜杠后仍然无法正常工作。错误是:GET wego/get_search_id.php
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-02
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    • 2011-05-13
    • 1970-01-01
    • 2014-10-14
    相关资源
    最近更新 更多