0

I am using a package called fetchJsonp. However, it keeps failing due to timing out. I am not sure if I am doing something wrong.

fetchJsonp('kayak.com/h/mobileapis/directory/airlines/homework', {
    jsonpCallback: 'jsonp',
  })
    .then(function (response) {
      return response.json();
    })
    .then(function (json) {
      console.log('parsed json', json);
    })
    .catch(function (ex) {
      console.log('parsing failed', ex);
    });

Any help is appreciated.

csshelper
  • 1
  • 1
  • Does this answer your question? [How to use JSONP on fetch/axios cross-site requests](https://stackoverflow.com/questions/43471288/how-to-use-jsonp-on-fetch-axios-cross-site-requests) – Shiladitya Aug 28 '21 at 03:31

1 Answers1

0

You will need to add https://www to your URL and fetch it like so:

<!DOCTYPE html>
<html>
  <head>
<meta charset="utf-8" />
<title>Fetch JSONP example</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch-jsonp/1.2.1/fetch-jsonp.min.js"></script>
  </head>
  <body>
<script>
  fetchJsonp("https://kayak.com/h/mobileapis/directory/airlines/homework", {
    jsonpCallback: "jsonp"
  })
    .then(function(response) {
      return response.json();
    })
    .then(function(json) {
      console.log("parsed json", json);
    })
    .catch(function(ex) {
      console.log("parsing failed", ex);
    });
</script>
  </body>
</html>
Ryan Le
  • 7,708
  • 1
  • 13
  • 23