Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda