1

I'm trying to understand the differences between JQuery GET method and Angular JS $http GET method. I'm not sure whether these two methods can be differentiated as per Synchronous and Asynchronous terms. Can anyone explain taking these below scenarios.

Angular JS Code:

// Simple GET request example:
$http({
  method: 'GET',
  url: '/someUrl'
}).then(function successCallback(response) {
    // this callback will be called asynchronously
    // when the response is available
  }, function errorCallback(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
  });

JQuery Code:

$("button").click(function(){
    $.get("demo_test.asp", function(data, status){
        alert("Data: " + data + "\nStatus: " + status);
    });
});

My question is - which implementation is more reliable and easy to use? Which one do you suggest?

coderpc
  • 4,119
  • 6
  • 51
  • 93
  • 2
    What exactly do you need to know? the question is no clear to me, please elaborate. The jQuery version does not seem to have an error handler (but it's possible to add one - https://api.jquery.com/jquery.get/) - BTW, they are both async calls – blurfus Sep 11 '17 at 17:06
  • Oh I see ! both are Async calls. So which one would u suggest me to use as per performance basis. @ochi – coderpc Sep 11 '17 at 17:24

1 Answers1

1

Both are asynchronous. Both handle errors and callbacks, just in different ways. .get() does it through method chaining, like so:

var jqxhr = $.get( "example.php", function() {
  alert( "success" );
})
  .done(function() {
    alert( "second success" );
  })
  .fail(function() {
    alert( "error" );
  })
  .always(function() {
    alert( "finished" );
  });

However, I'd say a better comparison would be Angular $http to jQuery.ajax(). And as far as performance or which one to use, take a look at this SO answer -> Should I use angularjs $http service for requests or jquery ajax if possible?

Spartacus
  • 1,468
  • 2
  • 15
  • 29