• 0

[jQuery] .ajaxStop callback function being executed multiple times


Question

Hello everyone,

I'm using jQuery but my problem is that my page variable is being incremented several times even when I'm using "page += 1" in the .ajaxStop callback function because it's being executed more than once after the first time it's used. I use that variable as a parameter passed to the Flickr API to get a specific page of data.

What is happening is that the first time that function is called, the callback function is executed once. I then call the same function from a "more" button to get the next set of results but that time the function is called twice, the next time it's called thrice, and so on... That means that I can get page 1, 2, 4, 7, 11, etc...

The AJAX functions I'm calling are basically the .getJSON function and some extra .getJSON functions called in its callback method [inside getPhotos(id)]

// This gets the user ID from a given Flickr user page URL
function getUserID() {
??? $("#moreRow").hide(350);

??? var usr = document.getElementById('user').value
??? var Req_addr = 'http://api.flickr.com/services/rest/?method=flickr.urls.lookupUser&api_key=' + API_key + '&url=http%3A%2F%2Fflickr.com%2Fphotos%2F' + usr + json
??? $.getJSON(Req_addr, function(data) {
??? ??? // Once the user is known, data about its photos is requested??? 
??? ??? getPhotos(data.user.id)
??? });

??? // This hides the user data panel??? 
??? $("#userInfo").hide(0);

??? // This hides the settings panel??? 
??? $("#settings").hide(0, function() {
??? ??? $("#loader").slideDown(750);
??? });??? 

??? // This is what displays the photos when all of the AJAX requests have received their responses (ajaxStop)
?? ?$("#photos").ajaxStop(function() {
??? ??? // the page counter is incremented for the next page to be requested next time
??? ??? page += 1
??? ??? 
??? ??? // Add the data for the newly obtained photos to the table
??? ??? addPhotosToTable()
??? });
}


Any hint as to what I'm doing wrong?

You can see the whole source here: http://luisargote.com/javascript/argote_flickr.js

2 answers to this question

Recommended Posts

  • 0
  • 0
  On 23/11/2010 at 12:09, Argote said:

Well, I got the answer from StackOverflow in case anyone runs into this later: http://stackoverflow.com/questions/4254891/jquery-ajaxstop-callback-function-being-executed-multiple-times

I came across a similar issue the other day. I was accidentally binding my events every time an ajax request was made! So when I clicked a button for example the code was executed several times resulting in some very strange results! I was tearing my hair out over it, though it was a serverside issue :laugh:

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Intel's next-gen desktop processors leak with a whopping number of cores by Taras Buria Intel's third-generation Core Ultra processors for desktop computers are on the way. If the latest leak is true, we are up for some significant updates in the Core Ultra 300 Series. @g01d3nm4ng0 on X posted a list of Intel's upcoming desktop processors, which includes seven SKUs ranging from entry-level Core Ultra 3 models to the flagship Core Ultra 9 with a rather whopping number of cores. According to the leak, the top-end model will feature 52 cores without hyperthreading. However, those cores are not like "classic" cores found in HEDT chips like AMD's Threadrippers. Instead, those 52 cores are divided into three categories: performance, efficiency, and low-power. The upcoming Core Ultra 9 reportedly features 16 performance cores, 32 efficiency cores, and 4 low-power cores. The cheapest Core Ultra 3 has four of each, 12 cores in total. Low-power cores are new to Intel's desktop processors. The current Core Ultra 200 chips feature the same hybrid configuration that was introduced with the 12th-gen Alder Lake chips: performance cores for demanding tasks and efficiency cores for lightweight tasks (up to 24 cores). Now, Intel wants to improve the efficiency of its chips further by adding another set of low-power cores, which were first introduced in the first-gen Core Ultra mobile chips (Meteor Lake). @jaykihn0 adds that Intel Nova Lake-S will support 8000 MT/s memory speed by default and 32 PCIe Gen 5 lanes and 16 PCIe Gen 4 lanes, totalling 48 lanes in CPU + chipset configuration. SKU P Cores E Cores LP Cores TDP Core Ultra 9 16 32 4 150W Core Ultra 7 14 24 4 150W Core Ultra 5 8 16 4 125W Core Ultra 5 8 12 4 125W Core Ultra 5 6 8 4 125W Core Ultra 3 4 8 4 65W Core Ultra 3 4 4 4 65W Today's leak aligns with previous reports about the upcoming Intel Nova Lake-S processors. However, Intel enthusiasts should probably get ready to switch platforms again, as the Nova Lake-S generation is rumored to require a brand-new LGA1954 socket.
    • My mb got a bios update but it just says... is this the fix? - Fix "AMD fTPM switch" option will be hidden. as long as set AMD CPU fTPM to Disabled - AGESA PI-1.2.0.3c released.
  • Recent Achievements

    • Explorer
      treker_ed went up a rank
      Explorer
    • Apprentice
      CHUNWEI went up a rank
      Apprentice
    • Veteran
      1337ish went up a rank
      Veteran
    • Rookie
      john.al went up a rank
      Rookie
    • Week One Done
      patrickft456 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      656
    2. 2
      ATLien_0
      272
    3. 3
      +FloatingFatMan
      176
    4. 4
      Michael Scrip
      157
    5. 5
      Steven P.
      136
  • Tell a friend

    Love Neowin? Tell a friend!