Somi Meer Somi Meer - 6 months ago 52
Javascript Question

Change Mouse pointer when ajax call

I want to change the mouse pointer to the "Wait" symbol when we run the AJAX call and return back to default pointer after completing the call. I have tried as follows but my problem is it's just working on Firefox until I dont click/press the mouse button. Here is my code:

function initializeAjax(url){
$('html, body').css("cursor", "wait");

try {
if (url.substring(0,4) == ".mdf") {
var database = window.location.pathname.slice(0,window.location.pathname.lastIndexOf('.mdf'));
var url = database + url;

returnedValues = null;
req.onreadystatechange = returnedValues;
nocache = Math.random();"GET", url+"&nocache = "+nocache, false);

$('html, body').css("cursor", "auto");
return req.responseText;
catch(err) {
return "Error 8";

Could anyone please help how to change above to solve the problem soo that it shud work in Firefox and IE too.


Have a look at the jQuery get method. It's very simple to use and handles callback as well, so you'll have no problem adding the code to set the mouse cursor back...


$('html, body').css("cursor", "wait");
$.get("yourajaxcall.url", function(data) {
    $('html, body').css("cursor", "auto");

    //  Success - do something with "data" here

}).error(function() {
    $('html, body').css("cursor", "auto");

    //  There was an error - do something else