简体   繁体   中英

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/ -> downloads 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM