doufu1939 2013-10-14 01:49
浏览 42

使用jQuery,Ajax和PHP返回/格式化HTML块 - 需要逻辑

I'm currently creating a website for comparing products. When someone does a search I've written code that goes off and finds/scrapes data for comparison.

Currently what I'm doing is having an ajax request for each company (currently 6 companies, although this could/will expand). The ajax request calls the php code which returns a json encoded array (company, name, price, type, size). As each request completes I'm using jquery to build the html block and then appending it to the page.

First Question: Is it better to use PHP to build the HTML or jQuery?

Now, I've got this working OK. However, now I'm getting to a point where I'm starting to think about using jQuery to manipulate the results (ie to sort and filter the results).

My thought process is basically to append all incoming ajax requests into another jquery array which I can then manipulate later as needed.

Second Question: Is the above logic sound, or am I missing a far simpler way of going about it?

Other Questions: Overall is this the right way (there might not necessarily be a right or wrong way, but is it the best way) of going about it? Is having multiple ajax requests going to make things die a horrible death the more users I get?

  • 写回答

1条回答 默认 最新

  • dquoj04882 2013-10-14 01:55
    关注

    I would consider caching the results per comparison. Check out php-apc cache.

    Consider building one object that contains all the results - possibly create an endpoint that can return data from multiple sources.

    You can then manipulate the object (reordering - filtering) and (re)create the markup.

    To create the markup - you could just build it with jquery/javascript.

    Or check out mustache.. It's a js .. and php templating engine. http://mustache.github.io/

    Good luck!

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用