skip to Main Content

I’m trying to run an ajax call to an external URL using “CORS Anywhere”.It worked fine but now resulting this error : Missing required request header. Must specify one of: origin,x-requested-with
I just can’t understand why this would happen

var CORS = 'https://cors-anywhere.herokuapp.com/';
$.ajax({
url: CORS + 'https://egtapp.com/bc/hotel/123456/inf/json/api/',
dataType: "json",
type: "GET",
success: function (jsonObject, status) {
    console.log(jsonObject)
},

});

3

Answers


  1. Attach header x-requested-with:

    var CORS = 'https://cors-anywhere.herokuapp.com/';
    $.ajax({
    url: CORS + 'https://egtapp.com/bc/hotel/123456/inf/json/api/',
    headers:{"x-requested-with":"XMLHttpRequest"},
    dataType: "json",
    type: "GET",
    success: function (jsonObject, status) {
        console.log(jsonObject)
    },
    });
    
    Login or Signup to reply.
  2. Please check url first. you r adding *CORS + ‘https://egtapp.com/bc/hotel/123456/inf/json/api/‘ * which means you want get something
    from following link:
    https://cors-anywhere.herokuapp.com/https://egtapp.com/bc/hotel/123456/inf/json/api/
    I don’t think this a valid url..
    After ensuring url, you can write:

    $.ajax({
    url:"your url from where u want to get data"
    method: "GET",
    success: function (jsonObject, status) {
        console.log(jsonObject);
    },
    error: function (err){
    console.log(err);
    });
    
    Login or Signup to reply.
  3. Mona, I think that is not from cors anywhere, that message comes from your target URL.
    So you should attach that header.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search