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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:31:57+00:00 2026-05-28T15:31:57+00:00

I want to move data variable to out of success function for other operation.

  • 0

I want to move “data” variable to out of success function for other operation.

$("a[class=note]").click(function( evt ){
                    var note = $(this).attr("value");
                    var preid = $(this).attr("id");
                    $.ajax({
                        type: 'GET',
                        url: 'style/ajax.php',
                        data: 'do=note&value=' + note + '&preid=' + preid,
                        success: function(data)
                        {
                            alert(data);
                        }
                    });
                });

For example php have Global pharase..

  • 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-28T15:31:58+00:00Added an answer on May 28, 2026 at 3:31 pm

    global var(which is the worse solution, but this is what you asked for):

    $("a.note").click(function( evt ){
                    var note = $(this).attr("value");
                    var preid = $(this).attr("id");
                    $.ajax({
                        type: 'GET',
                        url: 'style/ajax.php',
                        data: 'do=note&value=' + note + '&preid=' + preid,
                        success: function(data)
                        {
                            window.data = data;
                            alert(data);
                        }
                    });
                });
    

    global variable are dangerous, Maybe variable outside the success scope is enough?
    Var outside the success callback:

    $("a.note").click(function( evt ){
                    var note = $(this).attr("value");
                    var preid = $(this).attr("id");
                    var dataFromServer = null;
                    $.ajax({
                        type: 'GET',
                        url: 'style/ajax.php',
                        data: 'do=note&value=' + note + '&preid=' + preid,
                        success: function(data)
                        {
                            dataFromServer = data;
                            alert(data);
                        }
                    });
                });
    

    Last option is to have a hidden input that will store the data;

                        success: function(data)
                        {
                            $('#hiddenFieldId').val(data);
                            alert(data);
                        }
    

    Things to notice:

    1. I changed your selector from a[class=note] to a.note which is better.
    2. success is a callback which means it will not be fired until the response reach the client, until then your global\outside var\hidden input value will be null. if you don’t want the ajax to be asynchronous you can define it in the options like this:

      $.ajax({
        async: false, //  <---
        type: 'GET',
        url: 'style/ajax.php',
        data: 'do=note&value=' + note + '&preid=' + preid,
        success: function(data)
        {
            dataFromServer = data;
            alert(data);
        }
    });           
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to move some file to other place, using Java SE 1.6 So,
I want to move data from one database's table to another database's table. I
Where Visual Studio 11 beta Web installer download installation data? I want to move
We want to move data from Oracle to SQL Server, and make it available
I want to move some data from one table to another. I wrote a
I want to move about 800gb of data from an NTFS storage device to
I want to move a div down a page, and I want it to
I want to move a part, i.e. one subdirectory of an existing, private mercurial
I want to move something a set distance. However in my system there is
I want to move all files and folders inside a folder to another folder.

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.