最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - `the page is being unloaded` error - Stack Overflow

programmeradmin1浏览0评论

I was working with a NodeJS-ReactJS Isomorphic App, and when I click on a Link I'm getting an error saying

Uncaught (in promise) Error: Request has been terminated Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.

The first two reasons (offline and CORS) I heard about. What is the the page is being unloaded error means? How it may cause the browser not navigating to need.

I was working with a NodeJS-ReactJS Isomorphic App, and when I click on a Link I'm getting an error saying

Uncaught (in promise) Error: Request has been terminated Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.

The first two reasons (offline and CORS) I heard about. What is the the page is being unloaded error means? How it may cause the browser not navigating to need.

Share edited Oct 25, 2017 at 6:22 Asim K T asked Oct 13, 2017 at 8:56 Asim K TAsim K T 18.2k13 gold badges81 silver badges107 bronze badges 4
  • Is your link pointing to an external domain ? If so then better use a tag. – Fawaz Commented Oct 13, 2017 at 13:00
  • I am using a tag inside Link ponent. – Asim K T Commented Oct 25, 2017 at 6:21
  • why would you do that! Use any one of them at a time. – Fawaz Commented Oct 25, 2017 at 12:02
  • I don't understand. It's a react ponent. This is how a ponent works..! – Asim K T Commented Oct 30, 2017 at 6:29
Add a ment  | 

3 Answers 3

Reset to default 4 +50

Your Error is

Uncaught (in promise) Error: Request has been terminated

This error is caused when the request in the promise is terminated before it is resolved or rejected. This can happen if (Possible causes)

  1. the network is offline : There is a network failure and the connection to the url using which the request was being processed is lost.
  2. Origin is not allowed by Access-Control-Allow-Origin : The request is rejected due to absence of proper CORS headers.
  3. the page is being unloaded : The page making the request is closed before the request pleted.

Of the above reasons, the most probable cause relevant to your case would be either 1 or 2, since you get the error on clicking a Link to navigate to a ponent. Please check the requests being made by the new ponent that is being loaded using the Link.

Edit: If you look at the error message screen shot, it clearly states that the error occured at line no. 73194 of app.js at PromiseRequest in node_modules/superagent/lib/client.js.Request.crossDomainError. So the reason for your error is a CORS error which is described in number 2 above.

'cause Link ponent is using Location.push to do the redirection, while Location.push method cannot redirect to another domain.

So my solutions are:

  1. Use window.open('http://your.new.domain./index', '_self')
  2. Use <a href="http://your.new.domain./index">

It seems you have not enabled the cors in your node server. Suggested Steps:

  • npm install cors

  • use it in app.js (node server)

.

var cors = require('cors');    
var app = express();
app.use(cors()); //Enable CORS
发布评论

评论列表(0)

  1. 暂无评论