-1

Here when I trying to print response in browser console. It shows this error

Cross-Origin Read Blocking (CORB) blocked cross-origin response https://script.google.com/macros/s/AKfycbwmqG55tt2d2FcT_WQ3WjCSKmtyFpkOcdprSITn45-4UgVJnzp9/exec?url=http://35.230.52.177:8095/OneSoftTracking/rest/tracking/consignment/AE101632?hostname=aastha-enterprises.com&callback=jQuery1124008693115102408444_1561964934754&_=1561964934755 with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.`

While when I get data in Postman like:

This warning or error showing :

This is my code :

var settings = {
              async: true,
              crossDomain: true,
              crossOrigin: true,

              url: "http://35.230.52.177:8095/OneSoftTracking/rest/tracking/consignment/AE101632?hostname=aastha-enterprises.com",
              method: "GET",
              "headers": {
                  "Content-Type":"application/json",
                "Access-Control-Allow-Origin":"*",
                'Access-Control-Allow-Methods':'GET',

                'Access-Control-Allow-Credentials' : true,
                "Accept": "*/*",
                "Cache-Control": "no-cache",
                "Postman-Token": "bea2b074-eefc-473e-84d7-b680a07ed7df,dafa4f5c-94af-4efe-967f-75a9fe185a1e",

              },
              success: function(data) {
                  console.log("+++++SuCCESS");
                console.log(data);
              },
              error: function(error){
                  console.log("NOT SUCCEED");
              }
            }

            $.ajax(settings).done(function (response) {
              console.log(response);
            });

1 Answers1

0

You haven't shown us your real code.

The error message clearly shows a callback in the query string which isn't in your URL and shouldn't be added because you haven't said dataType: 'jsonp' in the jQuery ajax configuration.

Your real code is configured to use JSONP.

A JSONP response is a JavaScript program (specifically one which calls a single function with a set of arguments). The response you are getting from the server is an HTML document (the content type is text/html and not application/javascript).

The CORB error is the browser telling you that the response is HTML and not JSONP so it is refusing to try to execute it.

The Postman screenshot shows that you are expecting a JSON (still not JSONP) response (but you aren't getting that either).

You need to either:

  • Change the server to respond with JSONP
  • Change the request to ask for the correct data (and possibly also change the server to grant you permission to read it using CORS)

Further reading:


Notes about your code:

    async: true,

This is the default, get rid of it

    crossDomain: true,

This is the default for cross origin requests, get rid of it.

    crossOrigin: true,

This is the default for cross origin requests, get rid of it.

    method: "GET",

This is the default, get rid of it

        "Content-Type": "application/json",

You are making a GET request. There is no request body to describe the type of. This is nonsense. Get rid of it.

        "Access-Control-Allow-Origin": "*",
        'Access-Control-Allow-Methods': 'GET',
        'Access-Control-Allow-Credentials': true,

These are response headers, not request headers. Putting them on the request is nonsense. Get rid of them.

        "Accept": "*/*",

The default is almost certainly going to be fine. You probably don't need to override it.

        "Cache-Control": "no-cache",

The main config option "cache" is probably a better choice than explicitly setting the header.

        "Postman-Token": "bea2b074-eefc-473e-84d7-b680a07ed7df,dafa4f5c-94af-4efe-967f-75a9fe185a1e",

The odds of your server caring about this are remote. You can probably get rid of this.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • So sir , please suggest me what changes I have to do in this, to print this json data in console – Sandeep_Sh Jul 02 '19 at 06:05
  • @Sandeep_Sh — Either Change the server to respond with JSONP OR Change the request to ask for the correct data (and possibly also change the server to grant you permission to read it using CORS) – Quentin Jul 02 '19 at 07:44
  • @Sandeep_Sh — Either Change the server to respond with JSONP OR Change the request to ask for the correct data (and possibly also change the server to grant you permission to read it using CORS) – Quentin Jul 02 '19 at 07:52