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.

3
  • Are A and B on the same domain? Commented Dec 11, 2020 at 7:42
  • @Michel No they are on separate domains. Commented Dec 11, 2020 at 7:44
  • If we accept the ~2k limit as a given, 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. Commented Dec 11, 2020 at 7:53

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

How would I achieve both a POST and redirect simultaneously?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.