HTML/javascript client with a REST backend
I have previously written my web apps with a server side / html template language type design. I am interested in writing a static html client that uses javascript to fetch data from a restful service (ala couchdb). It dawned on me that I could not in one web request get both the static html file, and the json data that is used to populate it. This is not a problem by itself, but if I have a requirement for bookmarkable urls, how can I make this work?
/users/ -> do开发者_StackOverflow中文版wnloads users.html -> ajax request looks up users.
/users/bob -> downloads user.html -> ajax request looks up bob.
Is this a reasonable design? It gives me a lot of flexibility on the backend, as well as making it easy to collaborate with a designer. Anyone done something similar, or have an alternate suggestion?
Thanks!
That's fine except you are causing 2 requests for each page. Can you streamline it like this:
<script type="text/javascript">
var INITIAL_DATA = {json: 'data', here: 'from', server: 'side'}
onDocumentReady()
{
PopulateScreen(INITIAL_DATA);
}
</script>
Then you can use Ajax to refresh the screen with a different data set with a single request, later in the life of the page.
Eliminates the duplicate request issue.
精彩评论