By far, the most common class of errors I have are issues with the interface between javascript and server code. This includes having the javascript calling the wrong URL, passing the wrong data (particularly if the needs of what needs to be passed changes, and the javascript doesn't), and issues in turning data into html the same way that my app does.
Is there an easy way to deal with this? I'm developing currently using Zend Framework in PHP. I think the first couple of issues c开发者_StackOverflow中文版ould be avoided a bit by using Selenium, but I'm not sure how to deal with the data -> html issue. I'd love to have some kind of javascript equivalent to my ZF view helpers, but I'm not sure how possible that is.
On a well designed site, (public) URLs won't change. You are, of course, free to use whatever internal structure you wish.
If necessary, you should be able to generate JS just like you generate HTML. However, if you apply proper REST principles:
A REST API should be entered with no prior knowledge beyond the initial URI (bookmark) and set of standardized media types that are appropriate for the intended audience (i.e., expected to be understood by any client that might use the API). From that point on, all application state transitions must be driven by client selection of server-provided choices that are present in the received representations or implied by the user’s manipulation of those representations.
When it comes to making document manipulation proof against future restructuring, use libraries that support a robust element selection language, such as XPath or jQuery's selectors, rather than walking the DOM structure and use good IDs and class names that won't change.
精彩评论