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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:15:35+00:00 2026-05-26T09:15:35+00:00

I have one of those pesky variable scope problems with $.post. Before submitting a

  • 0

I have one of those pesky variable scope problems with $.post. Before submitting a form, I want to first check if the user has edited the content. I return false if the user hasn’t.

I’ve looked at a bunch of different examples on Stackoverflow and the general way to do this is to create a function and a callback function inside that function to handle the callback. My problem is that the when I call getReturned below, the callback does not get implemented (know this because form gets submitted and I’ve tried an alert). Btw, alert("No changes were made so text was not submitted."); gets called successfully.

What am I doing wrong?

function getReturn(callback, id, old_variable){
    var return_value = "ERROR";
    $.post('myURL', {"id" : id},
       function(data) {
          var text_from_server = $.trim(data[0].note_text);
          if (old_variable == text_from_server){
             alert("No changes were made so text was not submitted.");
             return_value = false;
             callback(return_value);
          } else {
            return_value = true;
            callback(return_value);
          }
        },
        "json"
     );
    };
var id = 123;
var old_variable = "foo";
getReturn(
       function(return_value){return return_value;/*alert("SUCCESS!");*/}, 
       id, 
       old_variable
);
  • 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-26T09:15:36+00:00Added an answer on May 26, 2026 at 9:15 am

    Since you are making an asynchronous request to test if the value has changed you have to always return false from your submit handler. In the callback, if the form was edited, you would then manually submit the form using form.submit(). Something like this:

    getReturn(   
        function(return_value) {
            if (return_value) {
                $("#myForm").submit();
            }
        },    
        id,    
        old_variable);
    return false;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing myself a forum, and I want to have one of those you
At work, we have one of those nasty communal urinals. There is no flush
It's one of those things that seems to have an odd curve where the
Given that I have a table that holds vehicle information and one of those
I have a GridView A that have many columns, one of those contains price
I have just recently battled a bug in Python. It was one of those
I have a Java program with Maven managing its dependencies. One of those dependency
I have a solution with differents projects in it, One those is an MVC
I have one question regarding unwanted extra jar files . First I had planned
sorry for possibly a very stupid question. I have one of those Visual studio

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.