A simple JSONP implementation

Related tags

Maps jsonp
Overview

jsonp

A simple JSONP implementation.

saucelabs

Installation

Install for node.js or browserify using npm:

$ npm install jsonp

Install for component(1) using component:

$ component install LearnBoost/jsonp

Install for browser using bower:

$ bower install jsonp

API

jsonp(url, opts, fn)

  • url (String) url to fetch
  • opts (Object), optional
    • param (String) name of the query string parameter to specify the callback (defaults to callback)
    • timeout (Number) how long after a timeout error is emitted. 0 to disable (defaults to 60000)
    • prefix (String) prefix for the global callback functions that handle jsonp responses (defaults to __jp)
    • name (String) name of the global callback functions that handle jsonp responses (defaults to prefix + incremented counter)
  • fn callback

The callback is called with err, data parameters.

If it times out, the err will be an Error object whose message is Timeout.

Returns a function that, when called, will cancel the in-progress jsonp request (fn won't be called).

License

MIT

Comments
  • Uncaught SyntaxError: Unexpected token :

    Uncaught SyntaxError: Unexpected token :

    When i doing request to Google Matrix services i get this error.

    Uncaught SyntaxError: Unexpected token :
    

    Help please, cause i don't understand what to do!

    opened by paladosss 11
  • loose debug version

    loose debug version

    could we loose the debug version to something like ^2.0.0 as we are using webpack, the client side require different version of the package might potentially increase the js size if we cannot dedup by the dedup webpack plugin. (so does the server side package size)

    Thanks

    opened by roderickhsiao 7
  • Add tests & automated testing with Sauce Labs

    Add tests & automated testing with Sauce Labs

    Adds a couple basic tests, and adds files for travis and zuul.

    Don't have write access to merge this myself. Also, someone needs to set up a hook for Travis.

    opened by feross 6
  • usage with plain html and javascript

    usage with plain html and javascript

    Very nice module, can you please make it compatible with plain HTML and JavaScript (I mean without nodejs). Can be done by putting module.export only if module exists. Or do you see any issue by doing that.

    opened by gagan-bansal 3
  • Update the npm version

    Update the npm version

    Would it be possible to release a new version?

    I’d like to use the cancel function introduced here without using a commit URL: https://github.com/webmodules/jsonp/commit/6eff760a4d708e337b5bf452fc74f614f1990458

    opened by bpierre 3
  • Return fn to cancel in-progress jsonp request

    Return fn to cancel in-progress jsonp request

    When destroying a page component, for example a video player, it’s important to be able to cancel in-flight jsonp requests so the callback doesn’t get called and all references to the player will be nulled so the player can get garbage collected quickly.

    If the callback were to hang around for another few seconds, this would delay GC and call a function that assumes the player is in a good state when it’s not.

    opened by feross 2
  • Empty Error object being returned

    Empty Error object being returned

    Hi, we are using jsonp to submit data to Pardot (salesforce), and using Sentry to log any issues.

    We started getting reports of failed submissions, and when digging into what's going wrong all I am seeing is that the JSONP callback is returning an error that is an empty object.

    Looking through index.js, I'm not sure how this is happening. It appears to me that the only time the callback is called with an error is in case of a timeout, in which case an Error object should be returned, not an empty object {}

    Is anyone able to shed some light on this behavior?

    opened by ErikAGriffin 1
  • cleanup() breaks.

    cleanup() breaks.

    I was enjoying jsonp() when i noticed cleanup() breaks because it attempts to get a .parentNode of a script that doesn't exist.

    You can reproduce this with:

    
    var jsonp = require('jsonp');
    
    jsonp('https://www.googleapis.com/freebase/v1/text/en/bob_dylan', function(){
      console.log(arguments);
    });
    
    jsonp('https://www.googleapis.com/freebase/v1/text/en/bob_dylan', function(){
      console.log(arguments);
    });
    
    

    One of those will fail to execute with the error Uncaught TypeError: Cannot call method 'removeChild' of null

    opened by yields 1
  • dependency 'debug' rely on es6 sytax, but jsonp is es5

    dependency 'debug' rely on es6 sytax, but jsonp is es5

    in the debug pkg, "main": "./src/index.js", dependency 'debug' use es6 syntax, but jsonp is es5, for this reason, when I build my project with webpack and exclude node_modules from babel, es5 syntax lead to errors such as const

    opened by Tony7lee 0
  • Add licence information in the package.json file

    Add licence information in the package.json file

    Hi,

    I use ScalaJS and to declare JS dependencies in ScalaJS, I need to pass through webjars (http://www.webjars.org/). So, to be able to use your lib in ScalaJS (I don't really use your lib, it's a lib I use that uses your lib 😉), I need to import you lib from NPM to webjars (possible via the UI of webjars). But because of licence reason, webjars refuses to import it: capture d ecran 2017-04-08 12 14 14

    So, is it possible or you to merge this PR and publish a 0.2.2 version ?

    Thanks :)

    opened by guizmaii 0
  • jsonp() Error: Timeout     at index.js:63 undefined

    jsonp() Error: Timeout at index.js:63 undefined

    fn: (error, data)=>{ console.log('jsonp()', error, data) }

    when I use jsonp( url, {}, fn) , I find status is 200 in network and &callback__jp0 is attached to the url.

    but response is json in firefox image

    and no response in chrome image

    I know the true response is __jp0&&__jp0( ... ) but I don't know how to make it

    this is my whole code(actually I have used {} or {timeout:"10000"} image

    opened by M3Dade 1
  • The param that I can't control

    The param that I can't control

    Why is param the first to automatically carry __jp0? As this: GET http://www.suggestion.baidu.com/su?wd=1&cb=__jp0 net::ERR_NAME_NOT_RESOLVED Can you help me? I don't need__jp0, and I want to control the param behind of 'cb='.

    opened by S16202228 0
  • How to handler 404 error? only timeout error now

    How to handler 404 error? only timeout error now

    It seems that only timeout will invoke the callback passed Timeout error, so how can I handle 404 error? I want the callback also be invoked if an onerror event dispatched.

    opened by bravelincy 0
Owner
webmodules
ES6 modules for web usage – on NPM
webmodules
Leon is a simple WhatsApp Bot.

Leon is a simple WhatsApp Bot.

TOXIC DEVIL 26 Dec 21, 2022
🏸 A simple plugin for image zooming without dependencies ~1.65KB gzip

ZOOOM.JS A simple plugin for image zoooming without dependencies. Only pure javascipt. Installation CDN JavaScript <script src="https://cdn.jsdelivr.n

Grzegorz Tomicki 13 Aug 30, 2022
Simple location picker on Leaflet map

Leaflet Location Picker Simple location picker with Leaflet map Usage: <label>Insert a Geo Location <input id="geoloc" type="text" value="" /> </lab

Stefano Cudini 37 Nov 17, 2022
This is a template project demonstrating how the MERN stack(Mongo, Express, React, Node) can be used, here we have the back end implementation and there is the React implementation as the front end

Versão em português MERN stack This is a template project demonstrating how the MERN stack(Mongo, Express, React, Node) can be used, here we have the

Douglas Samuel Gonçalves 2 Jan 22, 2022
Simple Library implemented using HTML, CSS and JavaScript. This is a simple implementation of JavaScript Modules of ES6.

Awesome-books A single page project with the porpuse of storing books' titles and authors. Built With CSS, HTML & Javascript. How to run in your local

Saadat Ali 7 Feb 21, 2022
Simple implementation of markup for Scriptable widgets.

Widget Markup Write Scriptable widgets with markup. Installation Just import the library script to your scriptable widget file. const {widgetMarkup, c

Rafael Gandionco 32 Nov 22, 2022
Plock is a responsive masonry layout implementation for React. Very simple to use and easy to understand.

About Plock ?? Plock is a responsive masonry layout implementation for React. Very simple to use and easy to understand. Can I see a demo? ?? The demo

Renato Pozzi 130 Dec 9, 2022
Simple Javascript implementation of the k-means algorithm, for node.js and the browser

#kMeans.js Simple Javascript implementation of the k-means algorithm, for node.js and the browser ##Installation npm install kmeans-js ##Example (JS)

Emil Bay 44 Aug 19, 2022
Simple implementation of online contract signature.

react-pdf-signaturer Simple implementation of online contract signature. Example online demo: https://buynao.github.io/react-pdf-signaturer/ Usage $ g

law 20 Nov 28, 2022
A simple implementation example (framework) of Deso Protocol's Smart Services.

This project serves as a simple implementation example (framework) of Deso Protocol's Smart Services. This framework comes with out-of-the-box SSL, MongoDB, dev/stage/prod environments, and modularity.

Hunter Paulson 5 Sep 22, 2022
A simple implementation of a task list application that can be used to add, remove, edit and check users tasks

"To-do list" is a tool that helps to organize daily activites. It simply lists the things which are needed to be done and allows user to mark them as complete. In this step of project, the CRUD (create, update, delete) methods are implemented. This simple web page is built using webpack and served by a webpack dev server.

Zahra Arshia 5 Mar 28, 2022
A dead-simple Bookmarklet and Chrome Extension implementation of something like Bionic Reading

What is it? Inspired by Bionic Reading, this Bookmarklet modifies a webpage to display the first half of each word in bold. Can also be installed as a

null 35 Dec 5, 2022
🦜️🔗 This is a very simple re-implementation of LangChain, in ~100 lines of code

??️ ?? LangChain-mini This is a very simple re-implementation of LangChain, in ~100 lines of code. In essence, it is an LLM (GPT-3.5) powered chat app

Colin Eberhardt 204 Aug 14, 2023
HTML5 Canvas Gauge. Tiny implementation of highly configurable gauge using pure JavaScript and HTML5 canvas. No dependencies. Suitable for IoT devices because of minimum code base.

HTML Canvas Gauges v2.1 Installation Documentation Add-Ons Special Thanks License This is tiny implementation of highly configurable gauge using pure

Mykhailo Stadnyk 1.5k Dec 30, 2022
An arbitrary size Bit-Vector implementation in JavaScript

BitSet.js BitSet.js is an infinite Bit-Array (aka bit vector, bit string, bit set) implementation in JavaScript. That means that if you invert a bit v

Robert Eisele 207 Dec 9, 2022
A solid, fast Promises/A+ and when() implementation, plus other async goodies.

when.js When.js is a rock solid, battle-tested Promises/A+ and when() implementation, including a complete ES6 Promise shim. It's a powerful combinati

The Javascript Architectural Toolkit 3.4k Dec 18, 2022
sprintf.js is a complete open source JavaScript sprintf implementation

sprintf-js sprintf-js is a complete open source JavaScript sprintf implementation for the browser and Node.js. Note: as of v1.1.1 you might need some

Alexandru Mărășteanu 2k Jan 4, 2023
Use CSS-in-JavaScript with themes for React without being tightly coupled to one implementation

react-with-styles Use CSS-in-JavaScript for your React components without being tightly coupled to one implementation (e.g. Aphrodite, Radium, or Reac

Airbnb 1.7k Dec 8, 2022
MultiLevelPushMenu jQuery Plugin implementation

Multi-level-push-menu by Momcilo Dzunic This jQuery plugin is inspired by Codrops MultiLevelPushMenu but unlike it not relaying on CSS 3D Transforms a

Momcilo Dzunic 808 Dec 21, 2022
Pure CSS (no JavaScript) implementation of Android Material design "ripple" animation

Pure CSS ripple effect (no JavaScript) CSS-only implementation of Android Material design "ripple" animation on click event Main advantage of this sol

Mladen Plavsic 334 Dec 11, 2022