0

When I am trying to make a http request to a server, I am getting the following network error in Internet Explorer and it is going to the error callback function:

SCRIPT7002: XMLHttpRequest: Network Error 0x2ef3, Could not complete the operation due to error 00002ef3

and in Chrome and Firefox it is going to the error callback function and showing the below error:

XMLHttpRequest cannot load the url. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

Below is the code:

HTTPRequestConts.GET_NAV = https://abc.xyz.com:8090/autoregisterbymobileno?id=ODgyODAyMDMzNg;;&cver=ios_3.0.1&dev=QTMzNkZCQUEtREVEQy00RUE4LTlDQTYtMjg0RDk0QkIyRDRB&lv=0&imei=MzUzMjg1MDcyNjY2ODQxMA;;&oem=100001&dm=QXBwbGU;&osv=aU9TMTAuMC4y";
var c = new HTTPRequest(HTTPRequestConts.GET_NAV);
c.setRequestMethod(HTTPRequestConts.GET), c.setCINResponseParser(), 
c.setCallback(new NavProxyCallback({
    onSuccess: function onSuccess(response) { console.log('success' + JSON.stringify(response));    },
    onError: function onError(err) {
       console.log('failure' + JSON.stringify(err)); }}, false)),
    HTTPClient.getInstance().send(c);
Lelio Faieta
  • 6,457
  • 7
  • 40
  • 74
Nandini Das
  • 1
  • 1
  • 2

2 Answers2

0

You are making a cross origin request.

This happens when you requests a resource from a different domain, or port than the one which the first resource itself serves.https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

Depending on what is causing it, you can either have the server handle the request and send it to the client, or enable the cross origin domain on your server where you are making the request to (not done make the mistake of enabling all domains)

How you do this depends on the server. Eg on node express https://enable-cors.org/server_expressjs.html Note in that link it enables all.

res.header("Access-Control-Allow-Origin", "*");

Instead replace the * with your own domain.

Ryan
  • 86
  • 8
-1

Set the contentType as ‘application/json; charset=utf-8‘ to resolve the issue.

Vj amal's
  • 9
  • 4
  • You can also refer this link -> http://stackoverflow.com/questions/14527387/script7002-xmlhttprequest-network-error-0x2ef3-could-not-complete-the-operati – Vj amal's Mar 22 '17 at 12:00
  • Why would that resolve the issue? There's no point in adding it to the request - it's a GET request - and the error message is a permissions problem, JSON doesn't get special treatment there. – Quentin Mar 22 '17 at 13:36