0

I have a web application and want to be able to pass an object ID via the URL:

www.example.com/?id=someObjectID

I then want to retrieve the Object data from the server (e.g. with an Ajax call).

What is best practice to handle this?

I came up with:

  1. analyse the URL with JavaScript.

    pros:

    • everything is pure client side JS

    cons:

    • there is no standard way for URL parameter handling in JS
  2. get the URL parameters server side and render them into the HTML response (e.g. inside a variable). Then make the ajax request client side.

    pros:

    • easy URL parameter handling server side (e.g. with express)

    cons:

    • parameter information makes a round trip to the server
    • server side rendering of the website (I could start render everything server side)

Are there any other options?

What are best practice here?

Is there any standard libraries/tools?

jbr
  • 6,198
  • 3
  • 30
  • 42
pat
  • 2,600
  • 4
  • 20
  • 21
  • 1
    There is no best practice, it depends entirely on your situation. However, you shouldn't be making excess AJAX requests for no reason. – user229044 Mar 13 '14 at 13:00
  • 1
    While it is true thee is no OOB solution to do it in Javascript, it's just a few lines function though, so better use it if you need/want to do it client-side. I see no big advantage doing it through querystrings if you act client-side through AJAX though – Laurent S. Mar 13 '14 at 13:01

0 Answers0