How do I set the beforesend
option in WordPress AJAX? I want to show loading option.
This is my code:
function showmyvideos() {
var datas="data";
var data = {
action: 'my_vids',
link: datas
};
ajaxurl= "http://localhost/wordpress/wp-admin/admin-ajax.php";
jQuery.post(ajaxurl, data,function(response) {
});
}
You have two options:
jQuery.ajax()
instead ofjQuery.post()
jQuery.ajaxSetup()
to change thebeforeSend
behavior globally.Reference: https://stackoverflow.com/questions/2257975/using-beforesend-and-complete-with-post
For posterity.
You can still use
$.ajax()
without having to use$.ajaxSeteup()
. All you need to specify is thetype
and make sure it is set toPOST
.As you can see, you can set different functions/events for
beforeSend
,success
andcomplete
.