Jquery AJAX return raw data or ready
This question already has an answer here:
I have certainly seen it done both ways. Here are some "bright-line rule" suggestions that you might consider.
(1) If the content is going to be treated by the app as "a black box" ... "don't look at, we're not going to have to interact with it, all we need to do here is to display it, whatever it is" ... then it might be entirely appropriate to let the server do all the work for you. (Especially if there are many possibilities, and "the server would know best," and "the app really doesn't have to give-a-damm.") You want to avoid creating unnecessary dependencies or duplication between the app and the server.
But ...
(2) If the content is something that the app is going to have to interact with, and/or is going to need to "style" or somesuch, then the logic within the app should probably be doing it. You want to avoid creating unnecessary dependencies or duplication between the server and the app. (Notice how the words, "server" and "app," are reversed in this paragraph.)
The concept is sometimes called "separation of concerns." If whatever-it-is is "more the server's concern than the app's," and "the app can afford to be 'unconcerned,'" then the server can hand-over au fait accompli. Otherwise, it probably should be handing you data.
In any case: "it is an engineering judgment-call for you, the engineer, to make and defend."
链接地址: http://www.djcxy.com/p/47882.html上一篇: 创建HTML:PHP服务器