Skip to content

Releases: lbwa/jsonp

Handle error event

20 Jun 15:40
Compare
Choose a tag to compare
  • Handle error event from JSONP element, and then set reject status from global callback Promise
    • Such as response code 404/500
    • We can use catch function to catch this reject status.
jsonp({
  url: 'http://localhost',
  // global function named `${jsonpCallback}` will be invoked when JSONP response
  jsonpCallback: 'jsonp',
  timeout: 5000,
  // eg. ?customCallbackParams=...
  callbackParams: 'customCallbackParams',
  urlParams: {
    // eg. ?key0=0&key1=1...
    key0: 0,
    key1: 1
  }
})
   .then(res => console.log(res))
+  .catch(err => console.error(err))

Support Promise API

20 Jun 16:00
Compare
Choose a tag to compare

Breaking change

  • Support the Promise API

  • Deprecated prefix option and callback option which has been replaced by Promise API

- new Jsonp({
+jsonp({
  url: 'http://localhost',
  // global function named `${jsonpCallback}` will be invoked when JSONP response
  jsonpCallback: 'jsonp',
  timeout: 5000,
  // eg. ?customCallbackParams=...
  callbackParams: 'customCallbackParams',
  urlParams: {
    // eg. ?key0=0&key1=1...
    key0: 0,
    key1: 1
  }
- prefix: 'prefixOfCallback'
- callback: ()=> {...}
})
+ .then(res => res)