Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support params #25

Open
asci opened this issue Oct 10, 2015 · 3 comments
Open

Support params #25

asci opened this issue Oct 10, 2015 · 3 comments

Comments

@asci
Copy link

asci commented Oct 10, 2015

Is it possible to add params to request?

@cjke
Copy link

cjke commented Nov 23, 2016

Old issue (but still open) so I thought I would drop in my HOF (es6, but the same logic could be used elsewhere):

// @flow
import coreJsonp from 'jsonp';

export default function jsonp(url:string = '', params:Object = {}, opts:Object = {}, fn:Function) {

    var query = url.indexOf('?') === -1 ? '?' : '&';
    query += Object
        .keys(params)
        .map(key => key + '=' + encodeURIComponent(params[key]))
        .join('&');

    return coreJsonp(`${url}${query}`, opts, fn);
}
// use
import jsonp from 'util/jsonp';

jsonp('http://jsfiddle.net/echo/jsonp/', { a:'123', b:'456' }, {}, (err, data) => {
    console.log(data);
});

@neptunian
Copy link

neptunian commented Aug 22, 2017

or use reduce:

let url = 'https://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos';
url = Object.keys(urlParams).reduce((acc,item,) => {
            return acc+'&'+item+'='+urlParams[item];
},url);

where urlParams is an object.

@S16202228
Copy link

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='.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants