你阿贾克斯JSON或HTML? [英] Do you Ajax JSON or HTML?

查看:192
本文介绍了你阿贾克斯JSON或HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是preferred方式做AJAX。

What is the preferred way to do AJAX.

如果它是为使用jQuery的AJAX PHP编写的搜索页面

If it was for a search page written in PHP using Jquery for the AJAX

你会如何处理响应

有响应包含所有相关的HTML /造型

a) Have the response contain all the relevant html/styling

B)发送纯JSON和有一个JavaScript函数围绕打造JavaScript变量的HTML /造型。

b) Send pure JSON and have a javascript function build the html/styling around the javascript variables.

我看到都有好处。 '一'显然是更容易,而B是更有效的(尽管GZIP可能会赚取差价可以忽略不计)。

I can see advantages to both. 'a' is obviously easier whilst 'b' is more efficient (although gzip would probably make the difference negligible).

推荐答案

我会说'一'是你主要是要坚持使用的选项。

I would say 'a' is the option you mostly want to stick with.

这是更容易保持一致的模板服务器端(可以重复使用他们非AJAX方案)。

It's much easier to keep consistent templates server side (you can reuse them in non AJAX scenarios).

客户端模板是不是超级优雅的(如果你要做到这一点,我建议是:的 http://ejohn.org/blog/javascript-micro-templating/

Client-side Templating isn't super elegant (if you're going to do it i suggest this: http://ejohn.org/blog/javascript-micro-templating/)

在造型方面,我会在页面加载时不会加载内容时,包括缩小的样式表。

In terms of the styling I would include a minified stylesheet when the page loads not when loading the content.

这篇关于你阿贾克斯JSON或HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆