Since I started diving into the world of serious ajax operations, one question has been on my mind. Let me illustrate with an example.
Imagine fetching a standard HTML page for a customer from the server. The URL could look like this:
/myapp/customer/54
Once the page is loaded, you want to enable ajax functionality that interacts with this particular customer. To achieve this, you need to include the id "54" in each request sent back to the server.
What would be the most effective/common way to accomplish this? Personally, I often resort to storing this information in hidden form fields. While easily accessible, it sometimes feels precarious. What if the document structure changes and the script stops functioning? Or what if that id is replicated for styling reasons months down the line, consequently breaking the page by having two identical ids?
Another approach could involve extracting the value "54" directly from the URL. Would opting for this method be more reliable? It might work seamlessly for simple scenarios but may become cumbersome for intricate cases where multiple ids or lists of ids need to be passed.
I am simply seeking guidance on a best practice - a solid solution that is both robust and elegant, receiving resounding approval.