jeudi 13 août 2015

Where is the best place to store supporting JSON on dynamic AJAX load?

Scenario: I have an HTML page with a dynamic modal dialog. Links on the page open the dialog, but with different contents according to the clicked link. Dialog contents are loaded using an AJAX request, and include only the required HTML - no html or head tags, for example.

In the dialog, there is a 'Status' display, and a couple of date pickers (e.g. 'Activated' and 'Removed'). As the dates change, the Status should update to show the current status according to the dates. That I can do, no worries.

In the application I have an enum for the Status, and I want the JavaScript in this dialog to make use of the same list of statuses as the server-side app. I figure the MVC should generate some JSON, listing the enum entries, for example:

{ "active": "Active", "removed", "Removed" }

Now the question! Where's the best place to put this JSON in the page, if it is loaded with the modal contents? Here are some options I've considered:

  • I could store it in a var in the head, but I don't need it to appear in every page in the application.
  • I could insert it into the head, or add it to the document element, when the modal is loaded, using a JS function called by the modal contents.
  • I could store it in the data tag of the Status display element.


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire