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

118
Views
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 answers
Answer question

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 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!