How can I execute a function that will run while the client is waiting for the server response? Here is my code. I looked up and found a .load() function, but how does that fit into this? Any help would be great! Thanks

$.ajax({
    type: "POST",
    url: "mail.php",
    data: {name: name.val(), email: email.val(), phone: phone.val(), subject: subject.val(), message: message.val()}
    }).done(function(){
        alert("Your message was sent. We will be in contact with you shortly.");
        window.location="index.html";
});

Recommended Answers

All 3 Replies

You mean for example if you want to show a spinning gif while submitting data? Here is an example I have used many times. ajaxStart().

$("#img1").click(function () {
    $("#div1").load("ajaxLoad.aspx");
});

$("#div1").ajaxStart(function () {
        $("#progress").css("display", "block");
    });

Thanks Jorge. Works great!

Excellent. Glad to hear.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.