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 9308091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:32:40+00:00 2026-06-19T00:32:40+00:00

i think this has something to with the function being asynchronous but i’m not

  • 0

i think this has something to with the function being asynchronous but i’m not sure. i think it’s a quick answer but i can’t figure it out.

i’m trying to check if images exist on the server. if they do, then set a variable. if they don’t then move on and check the next image.

every time i alert the variable though i keep getting 0. i know the urls are correct and everything. for some reason though i can’t get the variable. any tips?

    $('.rightPostContent img').each(function(){
            var c = $(this).attr('src');
            var pot1 = c.replace('_B.png','_pt1.gif');
            var pot2 = c.replace('_B.png','_pt2.gif');
            var pot3 = c.replace('_B.png','_pt3.gif');


        $.get(pot3)
            .done(function() { 
                var t = 3;
            }).fail(function() { 
        })  
        $.get(pot2)
            .done(function() { 
                var t = 2;
            }).fail(function() { 
        })          
        $.get(pot1)
            .done(function() { 
                var t = 1;
            }).fail(function() { 
        })  
        alert(t);
    });

the variable t wont alert anything, even though all pot images exist in this example.

  • 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-06-19T00:32:42+00:00Added an answer on June 19, 2026 at 12:32 am

    Exactly…
    This is asynchronous call… So when the control reaches your alert statement, the $.get()
    have not received the data from the server or whatever source yet.

    If you need to use that set value of t, you might wanna create a new function where this t needs to be passed. And then call that function from your done() or fail() call backs.

    function hereINeedTheT(t){
        //your code goes here.
    }
    
    $('.rightPostContent img').each(function(){
                var c = $(this).attr('src');
                var pot1 = c.replace('_B.png','_pt1.gif');
                var pot2 = c.replace('_B.png','_pt2.gif');
                var pot3 = c.replace('_B.png','_pt3.gif');
    
    
            $.get(pot3)
                .done(function() { 
                    var t = 3;
                    hereINeedTheT(t);
                }).fail(function() { 
            })  
            $.get(pot2)
                .done(function() { 
                    var t = 2;
                    hereINeedTheT(t);
                }).fail(function() { 
            })          
            $.get(pot1)
                .done(function() { 
                    var t = 1;
                    hereINeedTheT(t);
                }).fail(function() { 
            })  
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm hoping this question has a very simple answer. I can think of ways
How would I do this? I think this has something to do with editing
I think this question has been asked many a times but I've been searching
This has been driving me crazy. I think I have everything in place but
I know this topic has been discussed but I think it has some differences.
There are similar questions to this, but I don't think anyone has asked this
I don't think this question has been posed before, at least not in the
Ok, I think this is something simple, however I am being to stupid to
Ok, this this sounds like a newbie mistake... but I can't seem to figure
this is somewhat tricky to figure out I think, perhaps I am missing something.

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.