Skip to content

Support params #25

Open
Open

Description

@asci

Is it possible to add params to request?

Activity

  1. cjke commented on Nov 23, 2016

    @cjke

    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);
    });
    
    
  2. neptunian commented on Aug 22, 2017

    @neptunian

    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.

  3. xiaoni-ai666 commented on Mar 12, 2020

    @xiaoni-ai666

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions