Javascript http://localhost/undefined 404(未找到)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32467408/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
http://localhost/undefined 404 (Not Found)
提问by user3250335
I was not clear in my problem description. Let me try again.
我的问题描述不清楚。让我再试一遍。
NB. This is a problem common to my production, staging, and development sites (not just to my delevlopment site as the commenters seem to have thought).
注意。这是我的生产、登台和开发站点的常见问题(不仅仅是评论者似乎认为的我的开发站点)。
NB. This problem occurs bowsing with Chrome and not with Firefox.
注意。使用 Chrome 而不是 Firefox 会出现此问题。
The problem occurs at the site home page: 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/undefined404 (Not Found)". It always shows the error as occuring at "(index):1" which is the DOCTYPE line. Whatever is generating the problem, it is not that.
问题发生在站点主页:http: //www.example.com(或附加了“/index.php”)。页面加载成功,但 Chrome 开发者工具的控制台面板显示 404 错误。该消息显示为“GET http://www.example/undefined404 (Not Found)”。它总是显示错误发生在 "(index):1" 这是 DOCTYPE 行。无论是什么产生了问题,都不是那样。
The page is loading fine, I just get this odd message in the Developers Tools Console. (I probably wasn't clear about that in the original problem description.) Firfox's console shows no such error.
页面加载正常,我只是在开发人员工具控制台中收到这条奇怪的消息。(我可能在最初的问题描述中并不清楚。)Firfox 的控制台没有显示这样的错误。
I want to track down what is generating this error. In particular, I would like to find where Chrome is getting the "undefined" url. My guess (but only a guess) is that one of my many Javascript files is genrating a URL from an undefined variable. Chrome's location of the problem, "(index):1", is wrong. I would appreciate any ideas as to how to get a more useful error message out of Chrome: the name of the file where the URL was found would help. If I can do this without having set breakpoints in all my Javascript files one by one, that would be particularly nice. :-)
我想追踪是什么导致了这个错误。特别是,我想找到 Chrome 获取“未定义”网址的位置。我的猜测(但只是猜测)是我的许多 Javascript 文件之一正在从未定义的变量生成 URL。Chrome 的问题位置“(index):1”是错误的。关于如何从 Chrome 中获取更有用的错误消息的任何想法,我将不胜感激:找到 URL 的文件的名称会有所帮助。如果我能做到这一点而无需在我的所有 Javascript 文件中一一设置断点,那将特别好。:-)
The original question with URL's removed (I'm limited in the number of links I'm allowed with a reputation < 10) follows. You may not want to read it as people have been confused by it.
删除 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 notoccurring 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.
我们有相当复杂的 Drupal 网站。转到主页时,Chrome(版本 45.0.2454.85 m)控制台向我显示错误:“[URL 已删除] 404(未找到)(索引):1”。(我在本地计算机上使用开发站点,因为那里关闭了缩小功能。)
好吧,我想,我知道该怎么做:在任何文件中找到有问题的地方,挠头几次,得到一个绝妙的主意,并解决问题。一个小难点:问题肯定不是发生在索引,第 1 行(我认为这是“(索引):1”的意思)。错误消息中的“未定义”暗示但并不能证明冒犯者是我们大约十几个 JavaScript 文件中的一个。大概某个地方的某个变量是未定义的。那么我如何让 Chrome 咳出攻击发生的位置呢?它没有给我任何未定义的值 JavaScript 错误,只是 [URL removed]/undefined 上的 404。提前感谢您的任何想法。编辑:我忘了补充说 Firefox 没有显示这样的错误。
回答by Onza
I found where this issue could appear from.
我找到了这个问题可能出现的地方。
- Make sure that all the generated CSS (styles) that set a background-image or the like, where there's an url() actually point somewhere; if it doesn't point anywhere the error will set to the .html DOCTYPE.
- Check the src of your image tags; make sure that they are not set by JavaScript to undefined.
- Also check the src of your script files, even when it'd be much rarer in that case to happen.
- 确保所有生成的设置背景图像等的 CSS(样式),其中有一个 url() 实际上指向某个地方;如果它没有指向任何地方,错误将设置为 .html DOCTYPE。
- 检查图像标签的 src;确保它们没有被 JavaScript 设置为 undefined。
- 还要检查脚本文件的 src,即使在这种情况下发生的情况要少得多。
So yes it's awful that it actually doesn't point where the actual error is but in fact has to be with a lookup resource that it isn't able to find; we probably don't even want it to search. Eg. when the element is invisible and we don't set any image; but we still pass undefined it'll search for undefined and it'll not give you any hint of in which part of the tree the error is.
所以是的,它实际上并没有指出实际错误在哪里,但实际上必须使用它无法找到的查找资源,这很糟糕;我们可能甚至不希望它搜索。例如。当元素不可见并且我们不设置任何图像时;但我们仍然传递 undefined 它会搜索 undefined 并且它不会给你任何提示错误在树的哪个部分。
Since your page is too complex to know where it is, or if this is even the problem you are facing; this is the most I can tell; the only reason I could find it too quick was because of react dev tools told me right away of my render properties and the fact that the component was quite small.
由于您的页面太复杂,无法知道它在哪里,或者这是否是您面临的问题;这是我能说的最多的;我发现它太快的唯一原因是反应开发工具立即告诉我我的渲染属性以及组件非常小的事实。
回答by Vamsi Vempati
One other way to find what is causing this issue (when you have a decent sized solution) is to check if there is any undefined assigned to any html attributes/styles. We can check this by right clicking on body tag, Expand recursively, copy the HTML, paste it and search for undefined.
查找导致此问题的原因的另一种方法(当您有合适的解决方案时)是检查是否有任何未定义分配给任何 html 属性/样式。我们可以通过右键单击 body 标签,递归展开,复制 HTML,粘贴它并搜索 undefined 来检查这一点。
If there is undefined assigned to href/src/url etc. it might give you a clue on what is wrong.
如果有未定义分配给 href/src/url 等,它可能会给你一个错误的线索。
This can be fixed by not assigning undefined to those attributes.
这可以通过不将 undefined 分配给这些属性来解决。
回答by Senthil
images not loading properly for React Redux Dynamic Image Location,
图像无法正确加载 React Redux 动态图像位置,
I got the error
我得到了错误
Error: http://localhost/undefined 404 (Not Found)
so I tried below code its working
所以我尝试了下面的代码它的工作
{
user.id &&
<img className="img-responsive" src={`${API_URL}/${imageLocation}`} />
}
So when get dynamic data after its render new data imagelocation api url.
因此,在呈现新数据 imagelocation api url 后获取动态数据时。
回答by Julitillo
Many times it is fixed creating an .htaccess file with this content:
很多时候它是固定的,用这个内容创建一个 .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>