1

Using javascript, I'm trying to figure out how to pass a JSON Serialized array that contains multiple arrays, as a parameterized URL.

I've read multiple related articles on StackOverflow -- but they only addressed very basic singular arrays.[1]

[1] How to pass an array as a URL parameter?

Here's the context surrounding my specific use case, which involves two separate websites (A & B) that are on two separate domains:

Website A:

This website has shopping cart functionality that uses javascript, AJAX, jQuery, and utilizes localStorage to store product(s) that are added to the shopping cart.

Once the user is ready to checkout -- we redirect them over to Website B to complete the checkout process.

Example Shopping Cart Data:

The serialized JSON data below shows data for two separate products. Each product has 6 unique keys associated with it.

[
   {
      "cid":"68",
      "d":"12/26/2020",
      "tti":"75687708",
      "tt":"0800",
      "tn":"1",
      "q":"4"
   },
   {
      "cid":"67",
      "d":"01/09/2021",
      "tti":"75688769",
      "tt":"0909",
      "tn":"1",
      "q":"2"
   }
]

What the end result URL could potentially look like:

https://www.website-b.com/checkout?cid=68,67&d=12/26/2020,01/09/2021&tti=75687708,75688769&tt=0800,0909&tn=1,1&q=4,2

Website B:

This website will parse the URL using PHP in order to get the details of each product to process further (ie: product lookup and validation, etc).

Once the product(s) are validated the checkout page is populated and the user can complete payment and checkout.

CoastalPro
  • 83
  • 6
  • Are A and B on the same domain? – Michel Dec 11 '20 at 07:42
  • @Michel No they are on separate domains. – CoastalPro Dec 11 '20 at 07:44
  • If we accept the ~2k limit [as a given](https://stackoverflow.com/a/417184/1427878), then you could simply encode such a structure as above with 6 items _as_ JSON, and you’d still end up with only around 500 characters. Add proper URL encoding, and it would about double. Just `http_build_query`, to pass this a “standard” query string, would come in at about 500 to 600 characters with this example, so I would probably not bother inventing my own format here. – CBroe Dec 11 '20 at 07:53

1 Answers1

0
  1. The concept of URL itself do not have a limit but for browser URL there are.

  2. yes, you can pass an array.

But why do you want to past data in the URL params? i suggest that you use POST method and sent your data in the body as json format