0
$('#get_test').click(function(){
    $.post('ajax-request.php', {   
        act: 'start_test'
    }, function(data) { 
        var jstring = $.parseJSON(data);

So now in jstring I have data associated with english_word and russian_word. How could I save russian_word data in an array and use it in a different function?

1
  • can you post the data format. Commented Aug 8, 2016 at 8:52

2 Answers 2

1

If I understand you correctly, you could either pass the data directly to the other function within your success handler function like so

$('#get_test').click(function(){
    $.post('ajax-request.php', {   
        act: 'start_test'
    }, function(data) { 
        var jstring = $.parseJSON(data);
        myFunction(jstring.russian);

or you could persist the data to a scoped variable :

var russian=[];
$('#get_test').click(function(){
    $.post('ajax-request.php', {   
        act: 'start_test'
    }, function(data) { 
        var jstring = $.parseJSON(data);
        russian=jstring.russian;

and then pick up the value in your function :

   function myFunc(){
     Console.log(russian);
   }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Scoped variable was what I need))
0

declare a new array variable, and directly put the value from "jstring" using dot operator.

$('#get_test').click(function(){ $.post('ajax-request.php', {
act: 'start_test' }, function(data) { var jstring = $.parseJSON(data);

   var russian_word = new Array();
    russian_word = jstring.russian_word;

}

this will give you array of "russian_word".... i hope it would work for you...thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.