像这样:
var cancelMe = setTimeout(function() { $('#loading').show(); // assuming your loading element has the id "loading"}, 2000); // show loading element in 2 secondsjQuery.ajax({ url: "loadData.php", dataType: 'json', type: 'GET', success: function(result){ showResultsToUser(result); clearTimeout(cancelMe); // don't run if it hasn't run yet $('#loading').hide(); // hide the loading element if it's shown }});


