jQuery $ .post()与$ .get() [英] jquery $.post() vs $.get()
问题描述
我需要检索一个简单的页面并使用它返回的数据. $.post()
和$.get()
之间应该有一个区别吗?
I need to retrieve a simple page and use the data that it returns. Is there any difference between $.post()
and $.get()
should I be using one over the other?
我不打算随请求提交任何数据.
I don't plan on submitting any data with the request.
推荐答案
如果您只想从html文档中检索内容,请使用$.load()
.
If you just want to retrieve the contents from an html document, use $.load()
instead.
您甚至可以通过提供其他选择器从该文档中检索部分信息:
You can even retrieve partial information from that document by providing an additional selector:
$('#result').load('ajax/test.html');
$('#result').load('ajax/test.html #justThisContainerPlease');
请参见 http://api.jquery.com/load/
要更笼统地回答您的问题,无论对服务器使用的是POST
还是GET
请求都没有太大区别,它取决于您要发送的数据量.通常,GET
请求被限制为2083(因为IE限制了查询字符串).因此,如果要发送大量数据,则应使用POST
请求.
To answer your question more generally, its no big difference whether you're using a POST
or a GET
request to a server, it depends on the amount of data you need to send. Typically, a GET
request is limited to 2083 (because IE limits the query-string). So if you have a lot of data to send, you should use a POST
request.
从技术上讲,GET
请求应该稍快一些.因为在内部仅发送一个数据包,而不是至少发送两个数据包(一个用于报头,一个用于发送主体).但这确实是高性能优化.
Technically, a GET
request should be slightly faster. Because internally only one packet is sent instead of at least two (one for the header and one for the transmission body). But that really is high performance optimizing.
这篇关于jQuery $ .post()与$ .get()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!