【问题标题】:Codeigniter redirecting to another folder with the same nameCodeigniter 重定向到另一个同名文件夹
【发布时间】:2019-01-15 15:49:29
【问题描述】:

我正在尝试在我的 Codeigniter 项目中实现 ajax-live-search 库。该库位于 application/third_party/jQueryLiveSearch/core

这个库有自己的 core 文件夹。

当我加载页面时出现问题,看起来 Codeigniter 从框架中获取了默认的核心文件夹,所以 Codeigniter 没有使用application/third_party/jQueryLiveSearch/core/jQueryLiveSearch.php,而是尝试在/core/jQueryLiveSearch.php 中找到它。这给出了 404,因为那不是正确的路径。

看起来 Codeigniter 的文件夹优先。

我能做什么?我无法将库移动到 Codeigniter 的 core 文件夹。我还尝试在routes.php 中创建路线。反正有没有告诉 Codeigniter 使用绝对路径?谢谢。

Error

【问题讨论】:

  • lib 文件夹的路径是什么?它在application 文件夹中吗?
  • 向我们展示您的文件夹结构。
  • @chalithageekiyanage 不,我刚刚注意到。我们在外面有图书馆。可能是这个问题,我现在检查一下。
  • @AbdullaNilam imgur.com/a/45zeUwd 问题可能是描述 chalitha 的问题。
  • 你能用ajax显示脚本代码吗?

标签: php ajax codeigniter


【解决方案1】:

由于您的库位于application 文件夹之外,您可以使用baseurl 访问它。

所以absolute path 到您的library 是:

echo site_url("/lib/jQueryLiveSearch/core/jQueryLiveSearch.php");

AJAX Live Search 插件中,您需要在jQuery Options 中提供url

jQuery(".mySearch").ajaxlivesearch({
loaded_at: <?php echo time(); ?>,
token: <?php echo "'" . $handler->getToken() . "'"; ?>,
max_input: <?php echo Config::getConfig('maxInputLength'); ?>,
url: <?php echo (APPPATH."/third_party/jQueryLiveSearch/core/AjaxProcessor.php"); ?>
onResultClick: function(e, data) {
    // get the index 1 (second column) value
    var selectedOne = jQuery(data.selected).find('td').eq('1').text();

    // set the input value
    jQuery('#ls_query').val(selectedOne);

    // hide the result
    jQuery("#ls_query").trigger('ajaxlivesearch:hide_result');
},
onResultEnter: function(e, data) {
    // do whatever you want
    // jQuery("#ls_query").trigger('ajaxlivesearch:search', {query: 'test'});
},
onAjaxComplete: function(e, data) {

}
});

【讨论】:

  • 库已正确导入,但在尝试发出 AJAX 请求时,它会将请求发送到错误的路径。 js代码中没有url,所以无法从js中更改请求url。错误仍然与描述的相同:(
  • 我试过你的代码,但它不起作用。我得到的最接近的答案是使用这个:url:“../application/third_party/jQueryLiveSearch/core/AjaxProcessor.php”,但它说“forbidden 403”。我尝试使用 APPPATH 和 base_url() 但我仍然得到 403。
  • 您是否尝试关闭配置文件中的csrf_protection$config['csrf_protection'] = FALSE; ?
  • 是的,该参数设置为 false,但仍然给出 403。$config['csrf_protection'] = FALSE;
  • 在 github 的 Ajax Live Search 插件中,他们说将 core/AjaxProcessor.php 中的 Access-Control-Allow-Origin 标头更改为您的项目 URL。 Change the URL for Access-Control-Allow-Origin header in core/AjaxProcessor.php to your project URL. Currently it is https://ajaxlivesearch.com.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-01
  • 2013-04-01
  • 2021-02-19
相关资源
最近更新 更多