javascript - htaccess 修改漂亮的 url 会导致 Chrome Inspector 控制台中引导源映射错误的无休止的 javascript 循环
问题描述
.htaccess mods 和处理漂亮 URL 的初学者。
我有一个 php/bootstrap/mysql/javascript 页面: http://localhost/modules/posts/questions_all.php。
我想将http://localhost/modules/posts/questions_all.php/1234之类的页面重定向到原始页面。
我已经修改了 .htaccess 文件。
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^modules/posts/questions_all.php/?$ modules/posts/questions_all.php [NC,L]
它似乎重定向到原始页面,但会产生某种类型的无休止的 javascript 循环,一遍又一遍地附加部分代码,从而造成页面混乱。
在 Chrome 控制台检查器中,我收到此错误,该错误在页面的正常加载中不会发生。但是 /1234 在 URL 的末尾,错误是:
DevTools failed to parse SourceMap: http://localhost/modules/posts/questions_all.php/bootstrap.min.js.map
[Violation] Forced reflow while executing JavaScript took 32ms
SourceMap 的请求没有出现在原始页面中,该页面运行良好,没有控制台错误。
这似乎也发生在 Firefox 中,所以我认为这不是关闭 Chrome Inspector 中的 SourceMap 功能的问题吗?在 Chrome 检查器未使用的情况下,我仍然遇到此问题。
对于漂亮的 URL,我已将 htaccess mods 用于其他类似页面(带有引导程序)的相同方法,但我没有收到该错误并且它们运行良好,但不是此页面......!
先感谢您!
[编辑]:发现的问题在某种程度上与无限滚动的代码有关,但仍然不确定为什么我得到一个无限循环。代码的目的是不断加载数据,直到到达屏幕底部,然后停止。在没有将 /1234 添加到 URL 的情况下它可以正常工作,但是当添加 /1234 时,它似乎进入了无限循环并导致代码的其他部分也执行。
load_data 函数是用于检索数据的 AJAX 调用。
下面的代码:
//autoload portion. when scrolling reaches the bottom of the screen, triggers another load of data
$(window).scroll(function(){
if($(window).scrollTop() + $(window).height() > $("#load_data").height() && action == 'inactive'){
action = 'active';
start = start + limit;
setTimeout(function(){
load_data(limit, start, search, tag);//recursive loading function
}, 500);
}
});
解决方案
似乎上面的编辑不是问题。相反,它是 AJAX 调用函数中的 URL 引用。不知道为什么,但是使用如图所示的 htaccess,url 必须与 http:reference 一起完成,然后它工作正常。
$.ajax({
url:"questions_all_autoscroll_fetchdata.php" - original worked without htaccess mods, but no longer with htaccess mods
url:"/questions_all_autoscroll_fetchdata.php" - still did not work with htaccess mods
url:"http://localhost/modules/posts/questions_all_autoscroll_fetchdata.php" - worked fine with htaccess mods.
...});
如果有人可以提供解释,我将不胜感激。此外,如果有一种方法可以使其与相对 url 一起工作,那么了解它也会更有帮助。
推荐阅读
- php - php中的日期格式更改
- android - 如何使用搜索栏增加音量
- python-2.7 - 在 Anaconda 中安装 opencv python 包
- ios - 当核心数据实体没有变化时是否需要核心数据迁移?
- c++ - 为什么在编译时需要知道对象的内存配置文件以进行堆栈放置?
- c# - 文本框双向绑定在文本框未聚焦之前不会传输。每次按键都需要更新
- javascript - 在滑块上分组项目?
- php - How to get a variable value file from laravel blade
- css - 如何创建 CSS 样式的文本“标签”(不是 html 标签标签)?
- openlayers - 如何将geojson点添加到openlayers 3/4地图并使其可点击以打开其中包含属性的弹出窗口?