Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

119
Vistas
why is my ajax function being executed twice?

Hello I have problems with a function of the interact.js library what I want is that an action is executed when a box is moved or resized, for this I did the following

interact('.signer-box-update')
.draggable({
  inertia: true,
  restrict: {
    restriction: ".wrapper",
    endOnly: false,
      elementRect: { top: 0, left: 0, bottom: 1, right: 1 }
    },  
  autoScroll: true,
  onmove: dragMoveListener
  })
.on(['resizeend','dragend'], function (event) {
  var idSinger = event.target.getAttribute("idsinger"); 
  var wValue   = document.getElementById("widthValue").value ;
  var hValue   = document.getElementById("heightValue").value ;
  var xValue   = document.getElementById("coorX").value ;
  var yValue   = document.getElementById("coorY").value;
  if (idSinger!= null) {
    $.ajax({
      type: "POST",
      url: "${pageContext.request.contextPath}" +"/plantillas/plantillasAction_editCoordenadas.action?coorX="+xValue + "&coorY="+yValue +"&heightValue=" +hValue +"&widthValue=" +wValue  +"&idSingerDocument="+idSinger,
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      async: false,
      success: function(data) {
        alert(" ok");
      },
      error: function () {
        alert("not ok");
      }
    });
  }
})
.resizable({
  onmove: resizeMoveListener,
  edges: {left: true, right: true, bottom: true, top: true},
  modifiers: [
    interact.modifiers.restrictSize({
      min: { width: 100, height: 100 },
      max: { width: 400, height: 400 }
      })
    ],
  inertia: true
});

the idSinger value is assigned once a button is pressed with this I indicate that the call should be made, however what I get is that the call is not made until it has that value, this is correct, but once you have it before making the call is executed and then re-executed, do you have any idea how I can solve it?

this happens when running for the first time

first time

the method is not executed which is correct,the value is subsequently added by executing another method.

once this is done now always two calls are made, the first one is made by entering the function and the second one by entering the if

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Just a thought...

Split the "on" function into 2 different functions

.on(['resizeend','dragend'], function (event) {...}

to

.on(['resizeend'], function (event) {
  console.log('resize triggered')
})
.on(['dragend'], function (event) {
  console.log('drag end triggered')
})

My presumption is that both are actually being triggered causing the function to execute twice.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda