简体   繁体   中英

How can I parse a URL in Opal?

Let's say I have a URL that I want to parse, including the query string:

https://www.example.com/foo?bar=1&a[]=x&a[]=y

I would expect to be able to obtain a hash of the query string like:

{ "bar" => "1", "a" => ["x", "y"] }

How can I parse this using Opal? I looked at options like URI and even CGI from Ruby, but it seems they are unavailable.

Clearly, I could break apart this string myself (or possibly use the Addressable gem), but I would like to use some included library function instead.

hmdne on the Opal Slack has pointed me to opal-browser which includes the Browser::FormData.parse_query(s) method .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM