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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:32:26+00:00 2026-05-23T14:32:26+00:00

I have a javascript function called GetRequest() that calls the server with $.ajax() and

  • 0

I have a javascript function called GetRequest() that calls the server with $.ajax() and receives a json string:

function GetRequest(ThePage) {

RequestedPage = parseInt(ThePageNumber,10);

$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "../Pages/MyPage.aspx/GetPage",
    data: "{'ThePage':'" + ThePageNumber + "'}",
    dataType: "json",
    success: function (msg) {
        var data = msg.hasOwnProperty("d") ? msg.d : msg;
        OnSucessCallBack(data);
    },
    error: function (xhr, status, error) {
        alert(xhr.statusText);
    }
});

};

I have a function called ShowData() that calls GetRequest() and must wait until GetRequest receives its data before continuing.

function ShowData() {

//some code that determines the page number

GetRequest(ThePageNumber);

//wait until the data is in

};

I use GetRequest in several places so I can’t use its success function in the context of ShowData.

How do I make my function ShowData pause its execution until GetRequest is finished? I thought of changing the OnSuccessCallBack function and determine which function initially called GetRequest() but I’m not sure on how to best do this.

Thanks for your suggestions.

  • 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-23T14:32:27+00:00Added an answer on May 23, 2026 at 2:32 pm

    add a function pass-in to GetRequest like so:

    function GetRequest(pageNumber, successCallback){
    
      //I admit this isn't "elegant" but it's most assuredly readable
      var callback;
      if (successCallback == null) {
        callback = //default callback definition here
      } else {
        callback = successCallback;
      }
    
      //do everything else the same here 
      //except use the callback defined above
    }
    

    This gives you the flexibility to add in a separate callback handler for the onsuccess

    Alternately, do the same as above, but use the “onComplete” handler unless you need the data specifically on the return (it doesn’t appear as tho you do).

    I’m going to strenuously suggest that you do use callbacks for asynchronous code instead of trying to shoehorn in sync requests. It’s much better to just adopt a coding style that revolves around async requests when working in javascript, especially where you’re already doing AJAX (which is by definition intended to be async).

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

Sidebar

Related Questions

I have a javascript function that calls a generic function to make an ajax
I have a Javascript function that is called from the onchange method in a
I have a javascript function that manipulates the DOM when it is called (adds
Let's say you have a Javascript function that calls a web service method. So
I have a javascript function being called by an input type=image tag that generates
I have a JavaScript function that makes two consecutive Ajax requests using jQuery. I
I have a javascript function called showOrHide that toggles the display state of a
I use Google Chrome 7.0.x and I have the following javascript-function that gets called
I have a javascript function that is called onsubmit: function formCheck(){ return usernameCheck() &&
I have a java script function that i have called on body load mousemove()

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.