Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6759135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:53:46+00:00 2026-05-26T13:53:46+00:00

First of all I’d like to precise that I’ve read all the jQuery called

  • 0

First of all I’d like to precise that I’ve read all the “jQuery called twice” suggestions in this website, and none of them had the problem I’m facing.

It’s so simple that I don’t understand how comes it behaves like this.

  • I first call once and AJAX request that loads 20 records and put them in a table
  • then in those <tr> I add one (yet) picture, and I assign events like this :

:

$('.moderation_ok').click(function() {
  return decisionOk($(this));
}); 

then

function decisionBoutonOk(t) {
  var p=t.parent().parent().parent().parent();
  var id=p.attr('id').substring(3);
  AjaxDevisSendDecision(id, 1, null);
  return false;
}

and in the Ajax function, if everything went fine I read the result where there is another row to add:

function AjaxDevisSendDecision(id, decision, raison) {
  $.ajax({
    url: '/json/devis/decision/',
    dataType: 'jsonp',
    data : { id: id, decision: decision, raison: raison },
    context: this,
    cache: false,
  })
  .success( function (data) {
    if (data.success) {
      /* Success */
      for (var x in data.result) {
        var s=data.result[x];
        addRowIntoTable(s);
        refreshEvents();
      }
    }
  });
}

The problem I’m facing is the first call is perfect and works perfectly: click => call AJAX => result of AJAX call ok => add new row…

And now I’m stuck: if I click on the image of the second row, the AjaxDevisSendDecision() is called instantaneously twice. And really don’t understand what’s going on.

Any idea?

Edit: if there’s an exception in the event handler there’s no problem anymore:

function decisionBoutonOk(t) {
  var p=t.parent().parent().parent().parent();
  var id=p.attr('id').substring(3);
  p.css({ backgroundColor: '#5f5' });
  p.stop(true,true).hide('slow');
  AjaxDevisSendDecision(id, 2, null);
  eeqsf(); /* unknown function = raise exception */
  return false;
}

maybe this could give a clue to understand what’s going on…

For your information, here’s almost the whole source code:

function refreshEvents() {
  $('tr').each(function() {
    var id=$(this).attr('id').substring(3);
    if(typeof(globT[id].height)!='undefined') {
      return;
    }
    /* First time here = remember height in pixels */
    globT[id].height=$(this).children('.principal').children('.texte').height();
    $(this).children('.principal').children('.texte').height('89px');
    $(this)
      .mouseenter(function() {
        var id=$(this).attr('id').substring(3);
        var c=$(this).children('.principal').children('.texte');
        c.stop(true, true).animate({ height: globT[id].height+'px'}, 'slow');
        c.children('.choix_moderateur').stop(true, true).fadeIn('slow');
      })
      .mouseleave(function() {
        var c=$(this).children('.principal').children('.texte');
        c.stop(true, true).animate({ height: '89px'}, 'slow');
        c.children('.choix_moderateur').stop(true, true).fadeOut('slow');
        c.children('.raison_refus').stop(true, true).fadeOut('slow');
      });
  });
  $('.moderation_ok').click(function(event) {
    event.preventDefault();
    return decisionBoutonOk($(this));
  });
}

function decisionBoutonOk(t) {
  var p=t.parent().parent().parent().parent();
  var id=p.attr('id').substring(3);
  AjaxDevisSendDecision(id, 1,null);
  eeqsf();
  return false;
}

function AjaxDevisGet(nb, notassigned) {
  $.ajax({
    url: '/json/devis/liste/',
    dataType: 'jsonp',
    data : { nb: nb, notassigned: notassigned },
    context: this,
    success: function (data) {
      if (data.success) {
        for (var x in data.result) {
          var s=data.result[x];
          ajouteDevisDansDOM(s);
        }
        refreshEvents();
      }
    }
  });
}

function AjaxDevisSendDecision(id, decision, raison) {
  $.ajax({
    url: '/json/devis/decision/',
    dataType: 'jsonp',
    data : { id: id, decision: decision, raison: raison },
    context: this,
    cache: false,
  })
  .success( function (data) {
    if (data.success) {
      /* success=add each row in the result */
      for (var x in data.result) {
        var s=data.result[x];
        ajouteDevisDansDOM(s);
        refreshEvents();
      }
    }
  })
  .complete( function () {
    console.log('complete');
  });
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:53:47+00:00Added an answer on May 26, 2026 at 1:53 pm

    The problem was here:

    function refreshEvents() {
      $('tr').each(function() {
        ...
        blabla
        ...
      });
      $('.moderation_ok').click(function(event) {
        ...
        blabla
        ...
      });
    }
    

    After a successful Ajax call, I called refreshEvents() and in this function (see before) I always called $('.moderation_ok').click(function(event) {}. This meant: “add another function if we click on all the elements that belong to the class moderation_ok.

    I thought that when declaring functions like $('.moderation_ok').click(function(event) {} it overrides the click() behavior.
    Nope!
    I’m not deleting my question because my answer may be useful to others.

    Here’s the code I added before:

    $('.moderation_ok').unbind('click');
    

    And now it works like a charm.

    So, summary:

    When declaring functions like $('.moderation_ok').click(function(event) {} jQuery adds this function the click() behavior. If you do twice this, the function will be called twice and so on.

    In this case, use unbind() to remove any event handler: $('.moderation_ok').unbind('click');

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, there is no chance that this is a multi-user issue, as
First of all let me start by saying that this question is not about
First of all (in case this is important) I'm using ActiveState's Perl (v5.8.7 built
First of all there is a partial question regarding this, but it is not
First of all I would like to remark I am new with the concept
First of all, I would like to state the facts I know about 'inline',
First of all: this is not a homework assignment, it's for a hobby project
First of all, this is not a dupe of this question . You'll see
First of all this is not a question about how can I use http
First of all I have seen that there are many questions about unrecognized selector

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.