2

When do you use JQuery's Ajax method load and get? They seem to achieve the same things? Anybody knows? Thank you very much.

I'm not asking the difference between get and post methods. I'm asking Jquery get vs Jquery load methods.

4
  • @ErikvonAsmuth Guess OP is asking about about load vs get. Commented Jan 1, 2018 at 16:19
  • 1
    The docs have your answer: api.jquery.com/load and api.jquery.com/jquery.get. TL;DR: they both make a GET AJAX request, however load retrieves a portion of the requested page matching the selector you provided and appends it in to the selected element Commented Jan 1, 2018 at 16:20
  • Have you checked the documentation? Commented Jan 1, 2018 at 16:21
  • get vs load is like each vs map. You could call get and then put the data to an element, or just let load do it. Just like you could create an array, and then use each to push elements to it, or just let map do it. It's the difference between low level methods that can be used for anything, vs methods that have a more specific purpose. Commented Jan 1, 2018 at 16:22

1 Answer 1

0

To start with load uses get internally. When your server returns plain html and you want to set that html completely to an element, you can use load. Otherwise get or post

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

This method is the simplest way to fetch data from the server. It is roughly equivalent to $.get(url, data, success) except that it is a method rather than global function and it has an implicit callback function. When a successful response is detected (i.e. when textStatus is "success" or "notmodified"), .load() sets the HTML contents of the matched element to the returned data.

Sign up to request clarification or add additional context in comments.

2 Comments

so that is probably why they use Jquery get() when data returned like a queryset is returned instead when plain html is returned load is used.
You don't have to use load. You can use get. It's just load is made specifically for that use case.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.