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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:06:04+00:00 2026-06-08T23:06:04+00:00

I have problem with two functions. I want chcekResults run only when callAPI is

  • 0

I have problem with two functions. I want chcekResults run only when callAPI is finished.

My click event:

$("a#showA").click(function (e) {
    e.preventDefault();
    chceckResults(callAPI(apiKey));
});

and functions:

var Count = 0;
var ContractsArray = new Array();


function callAPI(yourAPIKey){
var enquiry = URL + yourAPIKey;
//alert(enquiry);
$.ajax({
 url: enquiry,
 type: 'GET',
 dataType: "jsonp",
 jsonp: "callback",
 jsonpCallback: "jsonpCallback2",
 complete: function (response, responseCode) {
 },
 success: function (json) {
     $.each(json.Contracts, function (index, contract) {
        // alert("Count before increament : " + Count);
        // alert(contract.ContractCode);
         ContractsArray[Count] = contract.ContractCode;

        // alert("Count after increament : " + Count);
        // alert("ContractsArray[Count]: " + ContractsArray[Count]);
         Count++;

        });
    }
 });
}

function chceckResults(){
alert("Count value in chceckResults : " + Count);
  for(var i = 0; i <= Count; i++){
    alert("ContractsArray[" + i + "]: " + ContractsArray[i]);
  }
}

I want chcekResults run only when callAPI is finished. How can I do that?

  • 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-08T23:06:06+00:00Added an answer on June 8, 2026 at 11:06 pm

    You want chcekResults run after callAPI is finished, there’s several possibilities, it’s run after callAPI is successful (I guess this is what you really wanted), or callAPI failed, or both.

    Since callAPI is making an ajax call, so you can put chcekResults in the success callback of the ajax.

    Such that:

    $.ajax({
      url: enquiry,
      type: 'GET',
      dataType: "jsonp",
      jsonp: "callback",
      jsonpCallback: "jsonpCallback2",
      complete: function (response, responseCode) {
      },
      success: function (json) {
      $.each(json.Contracts, function (index, contract) {
        // alert("Count before increament : " + Count);
        // alert(contract.ContractCode);
        ContractsArray[Count] = contract.ContractCode;
    
        // alert("Count after increament : " + Count);
        // alert("ContractsArray[Count]: " + ContractsArray[Count]);
        Count++;
       });
       // --------------------- Edit Begins -------------------------
       chcekResults(...);   // This is run after ajax response returns.
       // --------------------- Edit Ends -------------------------
      }
    });
    

    This is the quick way of doing it, if you want to make it more generic, you could pass the chcekResults as a callback to the ajax, so that if this callback is defined, run it, if not, ignore. This way, you can use this ajax with or without callback.

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

Sidebar

Related Questions

I have a problem to create a preprocessor macro function, that concatenates two Strings
Problem I have computed a probability density function that depends on two variables. I
I have two bits of code: a form and a jQuery function. My problem
I Have two problem in this Case : I want to pass a JSON
My problem is that I have two functions and one of the functions calls
I have a differential operator that acts on two functions. To simplify the problem
I have a Network class, which I want two virtual functions which I am
I have problem with not members of a class functions. I want to use
I want to have two .scrollable() functions and have two instances of .navigator(); My
I have two functions, one creates paragraphs dynamically and the other function selects (changes

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.