[英]Pros and con of $.ajax, $.load, $.getscript and object tag
I am using strict doctype and i want to embed a page within a page, for this i cannot use iframe as the doctype is strict, so found out 4 methods:我正在使用严格的文档类型并且我想在页面中嵌入一个页面,为此我不能使用 iframe 因为文档类型是严格的,所以找到了 4 种方法:
$.ajax()
.load()
$.getscript
<object>
tag <object>
标签can any one please tell me about the pros and con of all these approaches..谁能告诉我所有这些方法的优缺点..
Thanks谢谢
Ok, i'll attempt to answer this one.好的,我会尝试回答这个问题。
$.ajax()
is the root method of jQuery for ajax requests. $.ajax()
是 ajax 请求的 jQuery 的根方法。 it is so detailed, you have a lot of parameters to configure it (mostly, they are left as default).它是如此详细,你有很多参数来配置它(大多数情况下,它们保留为默认值)。 this complexity gave rise to the common $.get()
and $.post()
shorthands for easy use.这种复杂性导致了常见的$.get()
和$.post()
简写,以便于使用。 $.ajax()
is what you use if you want fine-grained control of the ajax request and what you want to do with it after. $.ajax()
如果你想对 ajax 请求进行细粒度控制以及之后你想用它做什么,你可以使用它。
.load()
is a "subfunction" of $.get()
(it uses get) but is has an implicit callback (aside from an optional callback). .load()
是$.get()
的“子函数”(它使用 get),但它有一个隐式回调(除了可选的回调)。 it instead loads the requested page, and places it in the element that precedes it as an escaped mark-up .它改为加载请求的页面,并将其作为转义标记放置在它之前的元素中。 this is good for loading pages that are already formatted to load into the target container.这对于加载已经格式化以加载到目标容器中的页面很有用。
.getScript()
is NOT meant to load pages. .getScript()
并不意味着加载页面。 it's to retrieve scripts and execute them on the page.它是检索脚本并在页面上执行它们。
<object>
tags however... <object>
标签但是...
The object element's purpose is to embed into a document a variety of different kinds of media files. object 元素的目的是将各种不同类型的媒体文件嵌入到文档中。 Historically, it was used primarily for placing ActiveX controls onto a page , but it can also be used to embed images (.gif, .jpg, and so on), movie files and applets, video files, PDF documents, Flash , and even HTML.历史上,它主要用于将 ActiveX 控件放置到页面上,但也可用于嵌入图像(.gif、.jpg 等)、电影文件和小程序、视频文件、PDF 文档、Flash ,甚至HTML。
although it can render HTML, it's not it's original purpose.虽然它可以渲染 HTML,但这并不是它的初衷。 It's meant for other media.它适用于其他媒体。
personally, i go for $.ajax() or $.get
to return JSON data and an HTML template, then have a template engine to build the page.就个人而言,我 go $.ajax()或$.get
返回 JSON 数据和 HTML 模板,然后有一个模板引擎来构建页面。 this way, JSON is light on the bandwidth, and templates are cacheable.这样,JSON 的带宽就很轻,而且模板是可缓存的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.