Skip to content

jsonpRequest

Mike Byrne edited this page Jan 25, 2022 · 2 revisions

description

Performs jsonp requests - by writing script tags into the page and setting up the callback function to run on success

requires

  • turnObjectToQueryString (handled automatically)

parameters

settings object - required:

  • url - required - url to send request to
  • callback - optional - function to run on response, defaults to "callback"
  • data - optional - data object sent as data in the request
  • onSuccess - required - what to do on success
  • onTimeout - optional - what to do if the request times out
  • timeout - optional - time in seconds to wait until assuming timeout, defaults to 5 seconds

returns

  • nothing

example usage:

jsonpRequest({
  url: 'https://api.instagram.com/v1/media/shortcode/9lMUPcwbzg',
  callback: 'my_callback',
  data: {
    access_token: "access_token"
  },
  onSuccess: function(data) {
    console.log('success!', data);
  },
  onError: function() {
    console.log('timeout');
  },
  timeout: 5
});