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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:30:10+00:00 2026-06-15T04:30:10+00:00

I am trying to assign the ajax callback function variable value to the existing

  • 0

I am trying to assign the ajax callback function variable value to the existing variable.

I have

function test(){

}

test.prototype.click=function(){

  this.count;

  //call ajax codes.....

  //ajax callback function
  ajax.callback=function(var1){
    //I want to assign returned data to this.count property. 
    this.count=var1.length
  }

}

test.prototype.show=function(){
   //wont work, it will show undefined...
   alert(this.count);
}

var t=new test();
    t.click();
    t.show();

I think it’s the scope issue but I don’t know how to solve this. Any idea? Thanks in advance.

  • 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-15T04:30:11+00:00Added an answer on June 15, 2026 at 4:30 am

    Yeah, using this within another scope causes all kinds of issues, so you need to work around this. One way is to avoid using this entirely by defining your function differently. For instance, you can define count like so:

    function test() {
    
        function count() {
        }
        ...
    

    And just use count() without the this. prefix.

    You can also set a variable to this and use that to refer to count within your other scope. For instance:

    var self = this;
    

    Scoping issues with this can be a pain in the neck and can occur when you do more OO with callbacks. It’s good you got introduced to this early on, so now you know to be on guard.

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

Sidebar

Related Questions

I'm trying to get an option value if clicked, and assign it to variable.
I am trying to assign objects in an NSMutableArray using this code - (IBAction)variablePressed:(UIButton
I'm trying to assign the output of this command ( that is in my
Im trying to assign a piece of a string, to a new string variable.
I'm trying to assign the value of an attribute of type Boolean. When I
I'm trying to assign the output of cURL into a variable like so: #!/bin/sh
I'm trying to assign an existing attachment (say it is attached to another post
I am trying to access variable 'dimensions' in my ajax response but not able
I'm trying to pass the name of a javascript function to a global variable.
Possible Duplicate: Return Value from inside of $.ajax() function I'm working on a CakePHP

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.