The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

.ajax() vs .get() -> get = 1 request and ajax = 2 requests???!!!

View previous topic View next topic Go down

.ajax() vs .get() -> get = 1 request and ajax = 2 requests???!!!

Post by JScript on June 4th 2015, 9:21 pm

Hello friends!

I'm surprised, perhaps by my lack of knowledge / information on the subject about using the .ajax() vs the .get()!

But in the console of my browser the .ajax() makes two requests for reading, while .get() only makes one!!!

Test the codes below to prove it...

.ajax() with the type option = 'get' - as is theoretically get() is a shortcut of ajax() - , according to information from the official website https://api.jquery.com/jquery.get/ :
Code:

console.clear();
var post = 1; // A number of post for testing!
jQuery.ajax({
   url: '/post?p=' + post + '&mode=editpost',
   cache: false,
   type: 'get',
   dataType: 'html',
   success: function(response) {
      console.log('Done!');
   }
});

.get() :
Code:

console.clear();
var post = 1; // A number of post for testing!
jQuery.get('/post?p=' + post + '&mode=editpost', function(data) {
   console.log('Done!');
});

Note that two requests are made using .ajax() and only one for the .get()!!!

The worst is yet to come, execute the code below using .ajax() and the type option: 'post' :
Code:

console.clear();
var post = 1; // A number of post for testing!
jQuery.ajax({
   url: '/post?p=' + post + '&mode=editpost',
   cache: false,
   type: 'post',
   dataType: 'html',
   success: function(response) {
      console.log('Done!');
   }
});

And now we only have a single request in .ajax() !!!

Does anyone want to comment?

JS

JScript
Forumember

Male Posts : 741
Reputation : 168
Language : PT-BR, EN
Location : Brazil

http://jscript.forumeiros.com/

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum