dmt dmt - 2 years ago 187
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 () {

Answer Source

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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download