weixin_33739541 2015-09-15 23:23 采纳率: 0%
浏览 21

加载ajax内容的快速方法

Lets say i have json which contains informations. What would be the best way to put the informations on site. Creating elements via js like (this is just part im interested in , inside ajax call) var div=document.creteElement("div"); var text=document.createTextNode("bla"); var img=new Img; img.src=json1.img; img.onload=function(){ div.appendChild(text); div.appendChild(img); } or putting them "in" like

body.innerHTML+="<div><p>blabla</p><img src='json1.img'/></div>"`

which one of there is better/faster/more efficient , or is there any better way how to put content into site via ajax? Also how does big sites that load tons of data from server handle this? Tons of data would take a lot of time to load

  • 写回答

1条回答 默认 最新

  • weixin_33724046 2015-09-16 00:03
    关注

    Ok, I understand now. To render content from ajax you have 3 choices:

    1. Load the data with an ajax request ($.ajax in jquery or xmlhttprequest from scratch) and then create elements and insert into DOM. This solution is very bad because it is unmaintainable.
    2. Load data using ajax and use javascript templates like Underscore template (_.template) or Handlebars (http://handlebarsjs.com/). This is a very useful solution.
    3. Load data using ajax and use a very powerfull system views like React JS. I love it and it's very intuitive and easy to use to have a good performance without a lot of work from your part. "Template system" is very cool and easy (like using html). I will use react if I were you :) https://facebook.github.io/react/
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测