Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

233
Views
Después de <a> hacer clic, espere a que se complete la función y luego haga clic/procese de nuevo

Estoy usando jQuery.get para hacer una solicitud AJAX. Cuando el usuario hace clic en <a> , envío una solicitud al servidor a través de jQuery.get y luego actualizo la <div id='aaa'>ajax call back here</a> ;

Sin embargo, cuando el usuario hace clic en <a> muy rápido, los datos de retorno son más lentos que al hacer clic, y <div id ='aaa'></a> no coincide con lo que está almacenado en la base de datos.

Por ejemplo <div id='aaa'>10</div> , -1 cuando el usuario hace clic 1 vez. El usuario hace clic 5 veces y se supone que #aaa es <div id='aaa'>5</div> , pero como el usuario hizo clic muy rápido, el div muestra <div id='aaa'>8</div> . La base de datos del servidor se actualizó a 5 y cuando el usuario hace clic 1 vez más, el <div id='aaa'>8</div> cambiará a <div id='aaa'>4</a> porque el servidor el lado es 5

Sé que se trata de una solicitud de red AJAX que llevará un tiempo finito.

Entonces, ¿es posible que mi función espere hasta que jQuery.get . termine y se complete, y luego solo pueda hacer clic/procesar nuevamente? Probé la siguiente codificación, pero sigo teniendo el mismo problema con la mención anterior.

 var isPending = false function fastbtn(sid, t) { if (isPending) return; goodget('', 'plugin.php?id=ttt&do=realland&ac=' + sid + '&click=true'); } function goodget(url, rid) { isPending = true; jQuery.get(url, function(data, status) { ajaxget(rid); //this ajaxget is my program core template language, ajaxget(url,WaitId), return as XML format; }) .done(function() { // <--only fires on success //alert('ok2'); }) .fail(function() { // <-- only fires on error }) .always(function() { // <-- this always fires isPending = false; }); }
 <a href="javascript:;" onclick="fastbtn('watering')">some div ...</a>

ingrese la descripción de la imagen aquí

Verás que la numeración salta..

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puede usar setTimeout . Entonces

 <a href="javascript:void(0);" onclick="fastbtn('watering');">some div ...</a> var isPendingTimeout = null; function fastbtn(sid, t) { goodget('', 'plugin.php?id=ttt&do=realland&ac=' + sid + '&click=true'); isPendingTimeout = setTimeout(function(){ if (isPending == true) { clearTimeout(isPendingTimeout); ---- do what you want ------ } }, 25); return false; }

Espero que ayude a resolver su problema.

over 4 years ago · Santiago Trujillo Report

0

Reemplazaría a etiqueta con un button (ya que el propósito a las etiquetas es la navegación) y la mantendría deshabilitada al hacer clic a menos que el servidor envíe la respuesta.

 <button onclick="fastbtn('watering')">some div ...</button>

Después de recibir la respuesta, es decir, éxito o fracaso, habilite el botón nuevamente.

 var isPending = false function fastbtn(sid, t) { if (isPending) return; goodget('', 'plugin.php?id=ttt&do=realland&ac=' + sid + '&click=true'); } function goodget(url, rid) { isPending = true; $('button').attr("disabled", true) jQuery.get(url, function(data, status) { ajaxget(rid); //this ajaxget is my program core template language, ajaxget(url,WaitId), return as XML format; }) .done(function() { // <--only fires on success }) .fail(function() { // <-- only fires on error }) .always(function() { // <-- this always fires isPending = false; $('button').attr("disabled", false) }); }

EDITAR Actualización de la respuesta después de las entradas de doble pitido.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!