jquery $.post() vs $.get()

前端 未结 5 1083
[愿得一人]
[愿得一人] 2021-02-04 14:47

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

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-04 15:10

    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');
    

    see http://api.jquery.com/load/


    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.

    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.

提交回复
热议问题