1

Possible Duplicate:
Difference between $.ajax() and $.get() and $.load()

What I'm trying to accomplish is to change the data in the page without refreshing the page. By going through the documentation of jQuery I understand that I can use below methods. But I don't understand which method to use. They all look the same to me.

What's the difference between $.ajax vs $.post vs $.get vs $.load ?

I read the documentation but I couldn't get the proper understanding of the difference of the above methods. I'm new to jQuery. If someone can please explain the difference, that would be a great help.

Thanks

Community
  • 1
  • 1
Techie
  • 44,706
  • 42
  • 157
  • 243

3 Answers3

5

They do what they say they do.

  • $.ajax is the function used to send XMLHttpRequests
  • $.post is a POST wrapper for $.ajax
  • $.get is a GET wrapper for $.ajax
  • $.load is the same concept, but allows you to load the content into a selected element easily.
Barry Chapman
  • 6,690
  • 3
  • 36
  • 64
4

$.post and $.get are just shorthand for using $.ajax with a specified type. The same applies to load as well.

Difference between $("#id").load and $.ajax?

http://api.jquery.com/jQuery.post/ - It actually specifies it's a shorthand in like the second paragraph:

This is a shorthand Ajax function, which is equivalent to:

$.ajax({ type: 'POST', url: url, data: data, success: success,
dataType: dataType });

Community
  • 1
  • 1
David
  • 2,053
  • 2
  • 16
  • 26
2

post, get, and load are all shorthand wrappers for the ajax method:

The $.ajax() function underlies all Ajax requests sent by jQuery. It is often unnecessary to directly call this function, as several higher-level alternatives like $.get() and .load() are available and are easier to use. If less common options are required, though, $.ajax() can be used more flexibly.

JKirchartz
  • 17,612
  • 7
  • 60
  • 88