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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:25:38+00:00 2026-06-04T12:25:38+00:00

Setup: I am doing an ajax-jsonp call, which is working fine. The callback function

  • 0

Setup:

I am doing an ajax-jsonp call, which is working fine. The callback function of this changes value of a variable, “myVaraible”. Just after the call, there is some if-else logic which works on the value of “myVaraible”.

Here is the code:

    <script>
        function myfunction() {
            $.ajax({
                url: myURL,
                dataType: "jsonp",
                jsonp : "jsonp",
                async: false,
                jsonpCallback: "jsonpCallbackFn"
            });
        }

        function jsonpCallbackFn(mydata) { 
            alert("inside jsonpCallbackFn");
            if(something) {
                // change value of a variable "myVariable";
            }
        }

        $(document).ready(function() {
            $("#preview_button").mouseover(function() {
                myfunction();

                alert("after myfunction");
                // do some if-else logic based upon the value of myVariable which is updated by the call to myfunction()
            });
        });
    </script>

The Problem:

The ajax call remains ‘pending’, the control moves to the if-else block (effectively executing on the old/stale value of myVariable). And then the ajax call completes. In short, out of the 2 alert boxes, alert("after myfunction"); executes first and then alert("inside jsonpCallbackFn");

As you can see, I have already set async: false,, but looks like that is not working as expected. Can anyone tell me what am I doing wrong? Also, I am not sure if I have explained the entire scenario properly, please let me know if any more info is needed.

Thanks a lot.

  • 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-04T12:25:39+00:00Added an answer on June 4, 2026 at 12:25 pm

    From the $.ajax documentation:

    Cross-domain requests and dataType: “jsonp” requests do not support synchronous operation

    So, you’ll need to put anything that relies on the results of the request in the callback.

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

Sidebar

Related Questions

I have the following jQuery ajax call setup: function Testing() { var result =
I get a 401 Unauthorized when my ajax is doing a POST event this
I'm working to setup an AJAX action in rails 3 with the following code.
So, I'm doing a setup project, all written in VB.NET, and I need to
I'm trying to set up Rails (v3.2.2) to use multiple databases. I'm doing this
Setup: I am using JSPs and jQuery. There is a 'parent' page which holds
Setup: I have written a jQuery function to update table cells of table_2, when
I've got the following code: <script type=text/javascript> $(function(){ $(#AddMaps).submit(function(){ var $form = $('#AddMaps'); $.ajax({
Current Project Setup I've been working on a web-based chat, similar to Facebook chat.
I'm trying to handle a ViewExpiredException exception on an ajax call using primefaces 2.2.1

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.