W
W
WQP2015-01-17 16:50:34
JavaScript
WQP, 2015-01-17 16:50:34

How to pass variable values?

Hello, I have a code

$.ajax({
    url : '****',
    type : "GET",
    dataType : "jsonp",
    success : function(msg){
        var videoparam = [msg.response['url240'],msg.response['url360'],msg.response['url480'],msg.response['url720']];
    }
});

When requested, I enter all the data into the videoparam array. But the problem is that outside of $.ajax this array is not valid. Tell me how to make this array become valid.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Melnikov, 2015-01-17
@WQP

ajax is executed asynchronously, so you need to use callbacks

$.ajax({
  url : '****',
  type : "GET",
  dataType : "jsonp",
  success : function(msg){
    var videoparam = [msg.response['url240'],msg.response['url360'],msg.response['url480'],msg.response['url720']];
    callOtherFunction(videoparam);
  }
});

function callOtherFunction(videoparam) {
  /* здесь работаем с массивом */
}

www.wisdomweb.ru/AJAX/jquery.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question