2017-05-29 38 views
1

我的申請是ASP.NET Core 1.0 Web API。 Iam用Angular 2typescript開發前端。角度2錯誤:未捕獲(承諾中):狀態響應:0代表URL:null

如果我刷新網頁之前完全加載Google Chrome一切工作正常,但如果我做同樣的事情上Mozilla Firefox蔭收到以下錯誤-消息:

[error.service] An error occured: Object { _body: error, status: 0, ok: false, statusText: "", headers: Object, type: 3, url: null } app.e9e4671abf55fe5a53fc.js:936:46167 

s</ConsoleLogger.prototype.error TheNameOfMyWebSite.net/js/app.e9e4671abf55fe5a53fc.js:936:46167 
u</ErrorService.prototype.handleError TheNameOfMyWebSite.net/js/app.e9e4671abf55fe5a53fc.js:936:39646 
u</CustomHttp.prototype.request/< TheNameOfMyWebSite.net/js/app.e9e4671abf55fe5a53fc.js:936:38047 
a</CatchSubscriber.prototype.error TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:543:27790 
a TheNameOfMyWebSite.js:311:808 
[264]/</</</o</ZoneDelegate.prototype.invokeTask TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:8316 
onInvokeTask TheNameOfMyWebSite.js:176:9452 
[264]/</</</o</ZoneDelegate.prototype.invokeTask TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:8229 
[264]/</</</n</Zone.prototype.runTask TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:3362 
ZoneTask/this.invoke TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:9349 


ERROR Error: Uncaught (in promise): Response with status: 0 for URL: null 
Stack-Trace: 
[email protected]/js/polyfills.e9e4671abf55fe5a53fc.js:57:1180 
[email protected]/js/polyfills.e9e4671abf55fe5a53fc.js:57:796 
scheduleResolveOrReject/<TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:57:1803 
[264]/</</</o</[email protected]/js/polyfills.e9e4671abf55fe5a53fc.js:50:8316 
[email protected]/js/vendor.e9e4671abf55fe5a53fc.js:176:9452 
[264]/</</</o</[email protected]/js/polyfills.e9e4671abf55fe5a53fc.js:50:8229 
[264]/</</</n</[email protected]/js/polyfills.e9e4671abf55fe5a53fc.js:50:3362 
[email protected]/js/polyfills.e9e4671abf55fe5a53fc.js:50:367 
ZoneTask/[email protected]/js/polyfills.e9e4671abf55fe5a53fc.js:50:9396 

defaultErrorLogger TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:8:473 
ee</ErrorHandler.prototype.handleError TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:162:273 
next TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:176:14602 
Qe</EventEmitter.prototype.subscribe/i< TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:176:6258 
c</SafeSubscriber.prototype.__tryOrUnsub TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:211:3724 
c</SafeSubscriber.prototype.next TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:211:2960 
u</Subscriber.prototype._next TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:211:1927 
u</Subscriber.prototype.nextTheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:211:1574 
p</Subject.prototype.next TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:211:6849 
Qe</EventEmitter.prototype.emit TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:176:6006 
Xe</NgZone.prototype.triggerError TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:176:10237 
onHandleError TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:176:9812 
[264]/</</</o</ZoneDelegate.prototype.handleError TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:7683 
[264]/</</</n</Zone.prototype.runGuarded TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:2951 
[264]/</</</n.microtaskDrainDone/< TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:57:2461 
[264]/</</</n.microtaskDrainDone TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:57:2430 
drainMicroTaskQueue TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:477 
ZoneTask/this.invoke TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:9396 

,但該網站刷新很好,一切工作應該如何,除了Iam收到的錯誤。

我只發現this後,那裏的人有類似的問題。

Stackoverflow上的另一個人也有similar problem,但由於我沒有使用CORS,因爲前端和後端在同一個域上運行,所以這對我不起作用。

這個錯誤信息是什麼意思?我究竟做錯了什麼?

回答

0

這看起來像一個CORS問題。

Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources (e.g. fonts) on a web page to be requested from another domain outside the domain from which the first resource was served.

瞭解更多關於它here

基本上,您的Angular2應用程序託管在另一臺服務器上,而不是您要調用的API。

既然您使用的是ASP.NET Core 1.0 Web API,我建議您通讀微軟的Enabling Cross-Origin Requests (CORS)文檔。

+0

你好@mercador謝謝你的回答。 我們沒有使用CORS,因爲後端和前端運行在同一個域上。 –

+1

@MoritzSchmidt也許你的Firefox瀏覽器安裝了哪些塊腳本的插件? – mercador

+0

好主意,但即使我停用所有插件Iam得到相同的錯誤:/ @mercador –

相關問題