question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to pass url query params?

See original GitHub issue

How to pass url query params?

For eg: http://www.abx.com?x=2&y=3

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:37
  • Comments:30 (6 by maintainers)

github_iconTop GitHub Comments

392reactions
mislavcommented, Apr 6, 2018

The fetch() operation simply uses the exact URL string as it was given. To pass the URL query params, simply have them in the URL string as in our example above:

fetch("http://www.abx.com?x=2&y=3")

If you need to construct query param string from a hash and you use jQuery on your site, you can do:

var url = "http://www.abx.com?" + $.param({foo: "bar", baz: "kuuq"})
fetch(url)

Update: here is what the fetch standard recommends in their documentation (also see discussion in https://github.com/whatwg/fetch/issues/56):

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(...)

This requires that the browser implements url.searchParams. A polyfill might be needed for older browsers.

333reactions
DannyiCrackedcommented, Jul 9, 2016

If fetch is hoping to become a front runner as new technology to use it really should provide something as simple as accepting an object as a query string.

fetch('url.com', { qs: { a: 1, b: 2 } }) is pretty basic functionality offered by every other URI request technologies.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the recommended way to pass urls as url parameters?
Honestly, go with Google URL Shortener. Then you can just use the URL code in the url query string: ...
Read more >
URL parameters - How to pass it to the destination URL
You can pass URL parameter values to your tracking destination URL using the options available in ClickMeter. ... You can also add multiple ......
Read more >
A Beginner's Guide to URL Parameters - SEMrush
To identify a URL parameter, refer to the portion of the URL that comes after a question mark (?). URL parameters are made...
Read more >
Pass parameter values via query string | Integration | Samples
To pass in parameter values, simply append them to the query string at the end of the base URL. ... In the above...
Read more >
How to pass + in the url query string parameter? - MSDN
Page 1: string msg = "<t1> +2"; string encoded = Server.UrlEncode(Server.HtmlEncode(msg)); StringBuilder url = ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found