Ajax call on class returns old data

I’m facing this issue since days and I don’t know what to do, my problem is the following.

For example, I have this class:

class My_Class
{
public $attr;

public function __construct()
{
$this->dummy_function();
}

public function dummy_function()
{
$this->attr = 0;
add_action(‘wp_ajax_click_trigger_one’, array($this, ‘modify_value’));
add_action(‘wp_ajax_click_trigger_two’, array($this, ‘get_value’));
}

public function modify_value()
{
$this->attr = 1;
return $this->attr;
}

public function get_value()
{
return $this->attr;
}
}

But when I execute my code in the following order, I receive this:

new My_Class();
// Trigger click one — returns 1
// trigger click two — returns 0

I want my second click to return 1, why isn’t my class preserving the values changed? How can I achieve this?

Thanks.

Read more here:: Ajax call on class returns old data

Leave a Reply

Your email address will not be published. Required fields are marked *