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

  • Home
  • SEARCH
  • 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 6873945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:07:59+00:00 2026-05-27T04:07:59+00:00

Having some difficulty using a variable within an ajax() function. I know it is

  • 0

Having some difficulty using a variable within an ajax() function. I know it is because the variable is not in the scope of the ajax() call but not sure how to fix this. I’ve read a bit about closures and callbacks for things like this but not really sure how to actually apply that to my code.

Code summary: on click() I get user_notes via ajax, and on that success I pop up a dialog box displaying the user_notes (all this works so far). Where it breaks down is when I then try and do another ajax call when the “Save” button is pressed. In that second ajax call user_notes is undefined within that scope.

How can I use user_notes within that second ajax call?

 $(".editSaved").click(function() {
            save_id = $(this).attr('id');
            var user_notes;

            //GET USER NOTES
            $.ajax ({
                url:"journal-util.php",
                data:"q=0&f=user_notes&save_id="+save_id,
                success: function(user_notes){

                    //BUILD SAVE DIALOG
                    div="<div><textarea rows=15 cols=27 id='RowSave'>"+user_notes+"</textarea></div>";
//AT THIS POINT USER_NOTES HAS A VALUE
                    success="<div>Updated!</div>";
                    $(div).dialog({ 
                        buttons: { 
                            "Save": function() { 
                                var that = this;
                                var un = user_notes; //tried this, didn't work
                                $.ajax ({
                                    url:"journal-util.php",
                                    data:"q=0&f=update&user_notes="+un, //un is empty
                                    success: function(result){
                                        alert(result);
                                        $(that).dialog("close");
                                        //$(success).dialog();
                                    }
                                })
                            },
                            "Cancel": function() { 
                                $(this).dialog("close");
                            } 
                        },
                        modal: true,
                        title: 'Delete',
                        resizable: false
                    });
                }
            });
        });
  • 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-27T04:08:00+00:00Added an answer on May 27, 2026 at 4:08 am

    Try this solution

    un = $('#RowSave').val();
    

    Hope this solves your problem

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

Sidebar

Related Questions

I'm very familiar with using Enums in other languages, but I'm having some difficulty
I'm having difficulty parsing some JSON data returned from my server using jQuery.ajax() To
I'm trying to parse an mrss feed using jquery but am having some difficulty
I am having some difficulty writing a function that will search through a directory
I am having some difficulty using a UIWebView to render PDF files on the
I'm having some difficulty understanding how to validate a date (DOB) using MVC2. What
I have implemented drag and drop in my application, but am having some difficulty
I am having some difficulty in using the jQuery Validator plugin. I have a
I'm using the Joda-Time library with Java. I'm having some difficulty trying to turn
I am trying to generate a report using Oracle but am having some alignment

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.