javascript - Setting query string using Fetch GET request -


i'm trying use new fetch api: https://developer.mozilla.org/en/docs/web/api/fetch_api

i making request this:

var request = new request({   url: 'http://myapi.com/orders',   method: 'get' }); fetch(request); 

however, i'm unsure how add query string request. ideally want able make request url like:

'http://myapi.com/orders?order_id=1' 

in jquery passing {order_id: 1} data parameter of $.ajax(). there equivalent way new fetch api?

update march 2017:

url.searchparams support has officially landed in chrome 51, other browsers still require polyfill.


the official way work query parameters add them onto url. the spec, example:

var url = new url("https://geo.example.org/api"),     params = {lat:35.696233, long:139.570431} object.keys(params).foreach(key => url.searchparams.append(key, params[key])) fetch(url).then(/* … */) 

however, i'm not sure chrome supports searchparams property of url (at time of writing) might want either use third party library or roll-your-own solution.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -