duanliao5995 2010-01-06 07:05
浏览 93
已采纳

我应该使用XMLHttpRequest / JSON还是iFrame?

I have been making extensive use of XMLHttpRequests and JSON to fetch from a MySQL database and return records as arrays. It works perfectly.

Additionally, I have three cases in which I have the server (via PHP) formatting the data as a web page and creating bar charts (as opposed to sending arrays back to JavaScript for processing). Currently, I call the PHP file via a hidden iframe and then insert the HTML into a DIV (since I don't like certain aspects of iframes and prefer to not have them accessible).

Is using an iframe the best method or can I accomplish the same thing via a XMLHttpRequest and JSON? I'm asking because of the length of the data being returned. At present, it translates to a full page of data, but I want it to be extensible (e.g., perhaps a couple of pages of data in the future).

Thank you for any insights.

  • 写回答

1条回答 默认 最新

  • dongziche8030 2010-01-06 08:32
    关注

    If you want to get formatted html from other page and insert it in the current page dom the easiest way according to me is using the jQuery load methods. It make ajax request to a given url, gets the html and appends it to specified page element.

    Generally the two methods - passing JSON data and passing Formatted html are good for different things. I personally prefer to pass JSON data and format it with client script and html. In this way it is more reusable.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题