1

Doing tests locally on my computer:

index.hml

<!DOCTYPE html>
<html>
    <head>
        <!--script src="angular.js"></script-->
        <script src="i18next.js"></script>
        <script src="app.js"></script>
    </head>
    <body>
    </body>
</html>

app.js

i18n.init();

Error @ line 672 in i18next.js

xhr.send(payload);

NS_ERROR_DOM_BAD_URI: Access to restricted URI denied

  • How do I solve this error?
  • Optional: What does this line do?
TTT
  • 1,848
  • 2
  • 30
  • 60

2 Answers2

1

You are encountering a same-origin-policy issue (see http://en.wikipedia.org/wiki/Same-origin_policy). This means that either the port, domain, or protocol is not the same between the URI that you are sending a request TO and the URL that you are sending the request FROM.

You can overcome this by adding headers to your server side code:
Access-Control-Request-Headers
Access-Control-Request-Method

See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

Janac Meena
  • 3,203
  • 35
  • 32
-1

I have resolve NS_ERROR_DOM_BAD_URI error in my project (using ReactJS - handle API by axios) but I think my explaination an solution can help you:

  1. How did I get this error:

FE code:

headers:  {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json'
}

BE code (Spring Boot):

allowedHeaders("userLoginToken", "Content-Type")

Because I only allow 'Content-Type' in headers, but my header have redundant config 'Access-Control-Allow-Origin' and my BE not allow that.

  1. How did I resolve: Only delete 'Access-Control-Allow-Origin' in request headers and error was disappeared.

    headers: { 'Content-Type': 'application/json' }

Neil Nguyen
  • 349
  • 2
  • 7