Giter Site home page Giter Site logo

jsonp's Introduction

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

jsonp's People

Contributors

feross avatar forbeslindesay avatar juliangruber avatar max-mapper avatar rapind avatar rauchg avatar roderickhsiao avatar tellnes avatar tj avatar tootallnate avatar voronianski avatar yields avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsonp's Issues

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.

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

Mock jsonp

How can i mock this standalone function?

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: 6eff760

Specifying exact callback function name

At the moment, the code lets you specify a prefix for the callback. But when making the actual request, it appends a counter value to it.

We have a case where the remote server expects the callback function to have specific name else it does not send a response.

Can we add an option to prevent the automatic addition of a counter to the callback function name and use the one that the user provides directly?

Add nonce prefix

In case two copies of jsonp are inserted into a same page, the count increment could collide.

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?

Limit requests per second?

Hello dear I am using this great repo on my react redux .
Is there a way to limit request per second ?
Some Throttle or queue like with nginx ? But on client side

Module not found: 'jsonp'

I'm trying to write a react app and i installed jasonp via npm install jasonp. My code

import React, {Component} from 'react';
import { AutoComplete }   from 'material-ui';
import getMuiTheme        from 'material-ui/styles/getMuiTheme';
import MuiThemeProvider   from 'material-ui/styles/MuiThemeProvider';
import JSONP              from 'jsonp';

const googleAutoSuggestURL = `
  //suggestqueries.google.com/complete/search?client=youtube&ds=yt&q=`;

class MaterialUIAutoComplete extends Component {
  constructor(props) {
    super(props);
    this.onUpdateInput = this.onUpdateInput.bind(this);
    this.state = {
      dataSource : ['Test', 'Test2'],
      inputValue : ''
    }
  }

  onUpdateInput(inputValue) {
    const self = this;
    this.setState({
      inputValue: inputValue
    }, function() {
      self.performSearch();
    });
  }

  performSearch() {
    const
      self = this,
      url  = googleAutoSuggestURL + this.state.inputValue;

    if(this.state.inputValue !== '') {
      JSONP(url, function(error, data) {
        // handle results here
      });
    }
  }

  render() {
    return <MuiThemeProvider muiTheme={getMuiTheme()}>
      <AutoComplete
        dataSource    = {this.state.dataSource}
        onUpdateInput = {this.onUpdateInput} />
      </MuiThemeProvider>
  }
}

export default MaterialUIAutoComplete;

After executing it i get the error

Failed to compile.

Error in ./src/App.js
Module not found: 'jsonp' in /Users/dave/Programming/Web/cenote/src

 @ ./src/App.js 24:13-29

It is installed in cenote/node_modules/jasonp. Any idea why i get this error?

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

Why not throw an Error when script onerror?

when script error, throw an error in advance instead of waitting the callback in timer

script = document.createElement('script');
script.src = url;
// add onerror
script.onerror = function() {
    cleanup();
    if (fn) fn(new Error('Failure'));
}
target.parentNode.insertBefore(script, target);

browser support?

Hi, do you know what browsers/versions you are compatible with?

I am thinking about old IES of course.

Thanks

multiple jsonp requests on same page failing with timeout error

Hi,

I'm doing multiple jsonp calls from one page to get a set of images for each of the product that will be rendered on the page. Even though I see all the requests return response(status - 200) for each of the jsonp call, I'm only able to get the data for one product only(mostly its the last product on the page).

IMPORTANT: all the jsonp requests uses same callbackto return the content.

I'm using React component to render product list by iterating through an array. Every time a new product list component is called/created, i make the jsonp request to fetch the set of images and display on the page.

When my page renders I see only one of the product shows the list of images. And rest of the jsonp request end up in 'Timeout' error.

Can someone show me how to make these multiple jsonp requests each with the same jsonp callback that simply gets content for each of the product?
console-error
network-requests-success

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.