http:///localhost/undefined 404(未找到)

http://localhost/undefined 404 (Not Found)

我的问题描述不清楚。让我再试一次。

注意。这是我的生产、暂存和开发站点的常见问题(不仅仅是评论者认为的我的开发站点)。

注意。使用 Chrome 而不是 Firefox 会出现此问题。

问题出现在站点主页:http://www.example.com (or with "/index.php appended"). The page loads successfully, but the Console pannel of Chrome's Developer Tools shows a 404 error. The message reads "GET http://www.example/undefined 404(未找到)”。它始终显示错误发生在“(index):1”,即 DOCTYPE 行。无论生成什么问题不在于此

页面加载正常,我只是在开发人员工具控制台中收到这条奇怪的消息。 (我在原来的问题描述中可能并不清楚。)Firfox的控制台没有显示这样的错误。

我想找出产生此错误的原因。特别是,我想找到 Chrome 在哪里得到 "undefined" url。我的猜测(但只是一个猜测)是我的许多 Javascript 文件之一正在从未定义的变量生成 URL。 Chrome的问题位置“(index):1”是错误的。对于如何从 Chrome 中获取更有用的错误消息的任何想法,我将不胜感激:找到 URL 的文件名会有所帮助。如果我无需在所有 Javascript 文件中一个一个地设置断点就可以做到这一点,那就太好了。 :-)

删除了 URL 的原始问题(我被允许的链接数量限制为 < 10)如下。你可能不想读它,因为人们已经被它弄糊涂了。

We have rather complex Drupal website. When going to the homepage, the Chrome (Version 45.0.2454.85 m) Console shows me an error: "[URL removed] 404 (Not Found) (index):1". (I'm using the development site on my local computer because minification is turned off there.)
Okay, I think, I know what to do about that: Go find the offending spot in whatever file, scratch my head a few times, get a brilliant idea, and fix the problem. One little difficulty: the problem is surely not occurring at index, line 1 (which I assume is what "(index):1" means). The "undefined" in the error message suggests but does not prove that the offender is one of our about a dozen JavaScript files. Presumably some variable somewhere is undefined. So how do I get Chrome to cough up the location where the offense is occurring? It is not giving me any undefined value JavaScript errors, just a 404 on [URL removed]/undefined . Thanks in advance for any ideas.

Edit: I forgot to add that Firefox is showing no such error.

我找到了可能出现此问题的位置。

  1. 确保所有生成的 CSS(样式)设置背景图像等,其中有一个 url() 实际上指向某处;如果它没有指向任何地方,错误将设置为 .html DOCTYPE.
  2. 检查图片标签的源代码;确保它们没有被 JavaScript 设置为未定义。
  3. 还要检查脚本文件的 src,即使这种情况很少发生。

所以是的,它实际上没有指出实际错误的位置,但实际上必须与它无法找到的查找资源有关,这很糟糕;我们可能甚至不希望它进行搜索。例如。当元素不可见且我们不设置任何图像时;但是我们仍然传递 undefined 它会搜索 undefined 并且它不会给你任何提示错误是在树的哪一部分。

由于您的页面太复杂以至于不知道它在哪里,或者这是否就是您面临的问题;这是我能说的最多的了;我发现它太快的唯一原因是 React 开发工具立即告诉我我的渲染属性以及组件非常小的事实。

找到导致此问题的原因的另一种方法(当您有一个合适大小的解决方案时)是检查是否有任何未定义分配给任何 html attributes/styles。我们可以通过右键单击 body 标签来检查这一点,递归展开,复制 HTML,粘贴它并搜索 undefined.

如果未定义赋值给 href/src/url 等,它可能会给您一些线索,让您知道哪里出了问题。

这可以通过不为这些属性分配未定义来解决。

React Redux 动态图像位置的图像未正确加载,

我收到错误消息

Error: http://localhost/undefined 404 (Not Found)

所以我尝试了下面的代码其工作

{
 user.id &&
 <img className="img-responsive" src={`${API_URL}/${imageLocation}`} />
}

所以在渲染新数据 imagelocation 后获取动态数据时 api url.

多次创建包含以下内容的 .htaccess 文件已修复:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ / [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

我在 Angular 图像未定义时遇到了同样的错误。使用 *ngIf 问题已解决。

<div *ngIf="imageUrl"  [style.backgroundImage]="'url('+ imageUrl +')'" >"