0 votes
405 views
in jQuery by

What is the difference between jQuery.get() and jQuery.ajax() method?

2 Answers

0 votes
by (4.4k points)

There are following difference between jQuery.get() and jQuery.ajax() method: -

ajax():-

  • ajax() method is more powerful and configurable, it allows you to specify how long to wait and how to handle error and success
  • You are able to get direct access to the XHR-object by using ajax() method.
  • You have to deal with the returned data yourself with a callback.

get():-

  • get() method is a specialization to over ajax, it is used to retrieve some data.
  • get() is just a shorthand for ajax()
  • get() method returns the data to a callback. It only allows GET-requests.
0 votes
by (4.4k points)

Syntax for jQuery.ajax() and jQuery.get() method: -

Syntax of ajax() method: -
      jQuery.ajax({
                url: 'test.txt',
                dataType: 'text',
                type: “GET”,
                success: function(data) {
                        console.log(data);              
                }
       });

Syntax of get() method:-

       jQuery.get('test.txt',function(data){
             console.log(data)
       },'text');

Share:- Whatsapp Facebook Facebook


Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

Categories

...