camsong / fetch-jsonp

Make JSONP request like window.fetch
998 stars 158 forks source link

Optional callback on URL #45

Closed 24thsaint closed 6 years ago

24thsaint commented 6 years ago

I'm using fetchJsonp like so to access data on a resource which I have no control of...

  fetchJsonp(url, {
    method: 'GET',
    mode: 'no-cors',
    credentials: 'include',
  })
    .then(function (data) {
      return data.json();
    })
    .then(function (response) {
      $scope[dateTime] = new Date(response.timestamp * 1000).toLocaleString();
 // ... more code

However, due to fetchJsonp adding a callback query string on the request URL, my request fails:

Error: JSONP request to https://resource.com/api/param1/param1 timed out at fetch-jsonp.js:85

Actual network request:

https://resource.com/api/param1/param1?callback=jsonp_1514919479266_12080

Is there a way for me to remove the callback on the request url due to this case?

24thsaint commented 6 years ago

My bad, their server does not support jsonp.

https://github.com/camsong/fetch-jsonp/issues/32#issuecomment-309177577