简体   繁体   English

AngularJS SPA中Google Chrome控制台中的奇数请求失败

[英]Odd failed request in Google Chrome console in AngularJS SPA

I have an AngularJS single page application that sends and retrieves data from a C# Web API service. 我有一个AngularJS单页应用程序,可以从C#Web API服务发送和检索数据。 Both applications are hosted on Amazon Elastic Beanstalk. 这两个应用程序都托管在Amazon Elastic Beanstalk上。 Periodically I get a failed request in the Google Chrome developer console. 我会定期在Google Chrome开发者控制台中收到失败的请求。 The request is to http://singlepageapp.elasticbeanstalk.com/null . 该请求是http://singlepageapp.elasticbeanstalk.com/null It bugs me because I can't work out where it originated from. 这让我很烦,因为我无法弄清它的起源。 All Ajax requests in my application come from the same place, and always have the base URI ( http://mywebapi.elasticbeanstalk.com/ ) with 'api/' and the name of the Web API controller appended.The developer console shows the following: 我的应用程序中的所有Ajax请求都来自同一位置,并且始终具有基本URI( http://mywebapi.elasticbeanstalk.com/ )和'api /'并附加了Web API控制器的名称。开发者控制台显示了以下:

Request URL:http://singlepageapp.elasticbeanstalk.com/null
Request Method:GET
Status Code:404 Not Found

The raw request that causes the error is as follows: 导致错误的原始请求如下:

GET /null HTTP/1.1
Host: singlepageapp.elasticbeanstalk.com
Connection: keep-alive
Accept-Encoding: identity;q=1, *;q=0
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36
Accept: */*
Referer: http://singlepageapp.elasticbeanstalk.com/
Accept-Language: en
Range: bytes=0-1244

Chrome list the type as 'media' and the initiator as 'other'. Chrome将类型列为“媒体”,将启动程序列为“其他”。 Any ideas would be gratefully received. 任何想法将不胜感激。 Huge thanks in advance. 在此先感谢。

EDIT: I just got the error again and noted that the request was not to my web api, but to the elastic beanstalk single page application. 编辑:我只是再次收到错误,并指出该请求不是对我的Web api,而是对弹性beantalk单页应用程序。 My logic makes no (direct) requests to this URI, all these are initiated by the browser in response to the user clicking a link. 我的逻辑对这个URI不做任何(直接)请求,所有这些请求都是由浏览器响应用户单击链接而启动的。 In this case the 'Save' button on one 'page' after a successful save runs the following: 在这种情况下,成功保存后,在一个“页面”上的“保存”按钮将运行以下命令:

$location.path('/next-page');

It is this that triggers the errant request. 这是触发错误请求的原因。 This doesn't occur though when going to this URI directly via clicking a link in the menu. 通过单击菜单中的链接直接转到此URI时,不会发生这种情况。

Ok, found the issue. 好的,找到了问题。 The page in question allows the user to take a photo using their web cam. 该页面允许用户使用其网络摄像头拍照。 When they click the 'Save' button they are taken to another page. 当他们单击“保存”按钮时,将带他们到另一个页面。 However before this occurs the logic does the following: 但是,在此发生之前,逻辑将执行以下操作:

video.src = null;

where 'video' is the following element in the page: 其中“视频”是页面中的以下元素:

<video class="cssimageclass" autoplay></video>

Setting the src to null initiated the browser request. 将src设置为null会启动浏览器请求。 Removing this fixed the problem. 删除此问题已解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM