开发者

Dispatching in an HTML/Javascript Application

I am in the process of creating an HTML application, in the sense that there will only be one HTML page and the rest will be done as AJAX using jQuery.

I will be storing context in the hash of the URL to preserve the back button and allow external deep-linking from our main site. I will use onhashchange to detect a request for new content. With that, I would use a link such as <a href="#product/sku-1">Link</a> to cause the application to go GET /api/product/sku-1.js as JSON, after which I would need a dispatch strategy to route that JSON to the proper renderer.

My initial thought was a set of regexes in onhashchange to set the callback of the ajax call based on the requested resource, but that makes a large assumption that rendering is always 开发者_StackOverflowthe same for any given resource. I don't have any current requirements that this assumption breaks, but I hate to tie my hands this early in the game.

Have any of you any advice to offer on patterns that work for this problem? I can think of at least 3 ways to handle this right now, but I'd like some insight from anyone who has had a prior experience with this before I make a command decision and move out.


Just to clarify - are you planning to use a js page as the AJAX server? Why not use a webservice model? That way you can just have one webservice URL and call whatever functions as necessary with parameters derived from the # bookmark.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜