dmt dmt - 9 months ago 47
Javascript Question

AJAX Loading Icon

I am using the following AJAX to pull some post content into a lightbox. All works great but is a bit slow. Could anyone give me some pointers with adding a loader icon to the following code?

Thank you!

jQuery(document).ready(function ($) {


$(".getpostidlink").mouseover(function (event) {
var postlinkid = $(this).data("postid");
var data = {
action: 'getpostidhref_action',
postdata: postlinkid,
complete: function () {
$.post(getpostidhref.ajaxurl, data, function (response) {
inline: true,
width: "90%",
maxWidth: 800,
open: false,
onClosed: function () {


If you check the jQuery docs for the ajax method, there are a couple of params you can include to help here.

Specifically you could use beforeSend and complete to show and hide a loading icon before and after the ajax has completed.

See here for more info: