weixin_33738578 2012-11-13 01:41 采纳率: 0%
浏览 48

AJAX-使用JSON与echo HTML

I have the below ajax call.

jQuery.post('index.php',{
                        'option'    : 'com_one',
                        'controller': 'product',
                        'task'  : 'loadColors',
                        'format'    : 'raw',            
                        'design_id' : design_id,
                        'collar_id' : collar_id                        
                }).success(function(result) { 
                    jQuery('div#color_wrapper').html(result); 
                }).error(function() { 
                    jQuery('div#color_wrapper').html('<h1>ERROR WHILE LOADING COLORS</h1>');
                });

Method 1 It returns large set of HTML. Then those are assigned to the div#color_wrapper. What I do here is echo all the HTML I want in the model.php.

Method 2 I just got to know that I can get the data as a JSON object and render them inside the page using a JavaScript template.(handlebarsjs).

As far I understand It's client side processing(Method 2)vs server side processing(Method 1).

My problem is which method is faster? Which method is the industry standard? Are there any pros and cons of these two methods? What method should I use and Why?

Thanks

  • 写回答

4条回答 默认 最新

  • weixin_33682790 2012-11-13 01:43
    关注

    I think the JSON method is better, since there's less data to transfer for consecutive requests.

    If you're really that conscious about performance, you should precompile your templates.

    Additionally, if you precompile your templates, you don't even have to send handlebars.js to the client. You can send a much smaller handlebars.runtime.js to the browser, further decreasing load time!

    评论

报告相同问题?

悬赏问题

  • ¥25 关于##爬虫##的问题,如何解决?:
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误