0

Here I create english array, so I can use it in another function.

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

                        var jstring = $.parseJSON(data);

                        english = jstring.english_word;

Problem is to save in this array JSON data, and then use it in other places.

$(document).on('submit', '#quiz_form', function() {
     alert(englsih.length);
});

This alert shows me 0 length, though it should be 5 (MySql returns 5 objects).

ashkufaraz
  • 5,179
  • 6
  • 51
  • 82
  • 1
    You’re using both `englsih` and `english`. Another problem might be covered here: [How do I return the response from an asynchronous call?](http://stackoverflow.com/q/14220321/4642212). – Sebastian Simon Aug 10 '16 at 12:20
  • 1
    if you write `console.log(englsih );` instance `alert(englsih .length);` what is your ouput? – ashkufaraz Aug 10 '16 at 12:20
  • @ashkufaraz I tried both, but I didn't get any alert, seems like it just ignored. I corrected code from 'englsih' to 'english' – Sanzhar Suleimenov Aug 11 '16 at 14:34

1 Answers1

0

This code:

english = jstring.english_word;

should be

englsih = jstring.english_word;

I think that you should check your code seriously

Synchro
  • 35,538
  • 15
  • 81
  • 104
liumy
  • 81
  • 2