Estoy tratando de deshabilitar un botón después de hacer clic en él. Yo he tratado:
$("#ajaxStart").click(function() { $("#ajaxStart").attr("disabled", true); $.ajax({ url: 'http://localhost:8080/jQueryTest/test.json', data: { action: 'viewRekonInfo' }, type: 'post', success: function(response){ //success process here $("#alertContainer").delay(1000).fadeOut(800); }, error: errorhandler, dataType: 'json' }); $("#ajaxStart").attr("disabled", false); }); pero el botón no se desactiva. Cuando $("#ajaxStart").attr("disabled", false); el botón se desactiva.
Si bien esto no funciona como se esperaba, creo que la secuencia del código es correcta. Cualquier ayuda será apreciada.
Ponga $("#ajaxStart").attr("disabled", false); dentro de la función de éxito:
$("#ajaxStart").click(function() { $("#ajaxStart").attr("disabled", true); $.ajax({ url: 'http://localhost:8080/jQueryTest/test.json', data: { action: 'viewRekonInfo' }, type: 'post', success: function(response){ //success process here $("#alertContainer").delay(1000).fadeOut(800); $("#ajaxStart").attr("disabled", false); }, error: errorhandler, dataType: 'json' }); });Esto asegurará que deshabilitar se establezca en falso después de que se hayan cargado los datos... Actualmente, deshabilita y habilita el botón en la misma función de clic, es decir, al mismo tiempo.
En su código, simplemente deshabilite y habilite el botón en el mismo clic de botón.
Debe habilitarlo dentro de la finalización de la llamada AJAX
algo como esto
success: function(response){ $("#ajaxStart").attr("disabled", false); //success process here $("#alertContainer").delay(1000).fadeOut(800); },He resuelto esto definiendo dos funciones jquery:
var showDisableLayer = function() { $('<div id="loading" style="position:fixed; z-index: 2147483647; top:0; left:0; background-color: white; opacity:0.0;filter:alpha(opacity=0);"></div>').appendTo(document.body); $("#loading").height($(document).height()); $("#loading").width($(document).width()); }; var hideDisableLayer = function() { $("#loading").remove(); };La primera función crea una capa encima de todo. La razón por la que la capa es blanca y completamente opaca es que, de lo contrario, IE le permite hacer clic en ella.
Cuando hago mi ajax, me gusta esto:
$("#ajaxStart").click(function() { showDisableLayer(); // Show the layer of glass. $.ajax({ url: 'http://localhost:8080/jQueryTest/test.json', data: { action: 'viewRekonInfo' }, type: 'post', success: function(response){ //success process here $("#alertContainer").delay(1000).fadeOut(800); hideDisableLayer(); // Hides the layer of glass. }, error: errorhandler, dataType: 'json' }); });