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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:36:05+00:00 2026-05-27T15:36:05+00:00

In the following, the return statement is being executed before the call to $.get()

  • 0

In the following, the return statement is being executed before the call to $.get() finishes. How can I change this?

var aft = {};

aft.getToken = function (url) {

    var theToken;

    //Get the token value
    $.get(url, function (data) {

        theToken = $(data).find('input[name=__RequestVerificationToken]').val();

    }, "html");

    return theToken;

};
  • 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-27T15:36:05+00:00Added an answer on May 27, 2026 at 3:36 pm

    You can’t—at least not sensibly. While there is an async property you can set on jQuery ajax requests, I’ve had serious problems trying to use it with a false value in the past.

    Try to re-think what you’re trying to accomplish:

    var aft = { yourToken: '' };
    
    aft.setToken = function (url, callback) {
        $.get(url, function (data) {
            this.yourToken = $(data).find('input[name=__RequestVerificationToken]').val();
    
            if (callback)
               callback.apply(this);
        }, "html");
    };
    

    And then:

    aft.setToken("url.php", function() {
       alert("Token retrieved = " + this.yourToken);
    });
    

    Or, if your callback only needs access to the returned data, then you could more simply do

    if (callback)
        callback(data);
    

    And then

    aft.setToken("url.php", function(dataReturned) {
       alert("Ajax data retrieved = " + dataReturned);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I return nothing to the following post, I get an AJAX parse error:
Can someone explain why this exception is occuring the in the following LINQ query:
Why does the following return 0? <p id=g> <div>kk</div> <div>ee</div> <div>jff</div> </p> <script type=text/javascript>
I have following code return (EseshEntities.Current.Users.Select(u => new { Comunity = u.Apartment.Building.District.City })).ToList(); if
Why the following code will return obvious , surprise! (and lastly how come? ).
The query I'm trying to develop return the following: The total amount of units
I have an .erb file where I'd like to return the following text: Name
I am trying to come up with a query that will return comments following
The following works: public Date getDate() { return date; } and produces something like:
The following query looks the table ids and return the id if for example

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.