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/ :
.get() :
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' :
And now we only have a single request in .ajax() !!!
Does anyone want to comment?
JS
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