ajax - Assigning JSON value to a Variable that Resides Outside JavaScript Function -


i have question regarding json web services , ajax function. have declared javascript function below.

function setjsonser(){              formdata = {                 'email': 'clientlink@russell.com',                 'password': 'russell1234',                 'url': getvaria()             };                  $.ajax({                 url: "/apiwebservice.asmx/analyticsdatashowwithpost",                 type: 'post',                 data: formdata,                 complete: function(data) {                     alert("this set json in  "+json.stringify(data));                 }              });              $.ajax({                 url: "/apiwebservice.asmx/analyticsdatashowwithpost",                 type: 'get',                 data: formdata,                 complete: function(data) {                     alert("this json out  "+json.stringify(data));                 }             });  }  

as can see have alert json.stingify(data) statement , gave me result expected.

now want json response out of particular function setjsonser() assign avariable resides out side setjsonser() function.

i tried return json.stringify(data)) , json.stringify(data) statements did not put result out setjsonser() function.

the output must grab variable below.

function load(){ 

//-----------------------------------------------

setjsonser();  var labels = new array(); var values = new array(); var catogories = new array(); var arrayofarray = new array();  var rowdata = "return value of json.stringify(data)"; 

this variable used query draw chart using highcharts. give me clue how result of setjsonser() function?

thanks , regards, chiranthaka

you're getting bit mixed asynchronous nature of ajax.

the ajax event being fired, won't causing pause in execution of code, such, need implement callback.

this code isn't particularly nice, should give idea of how data needs handled.

function setjsonser() {     formdata = {         'email': 'clientlink@russell.com',         'password': 'russell1234',         'url': getvaria()     };      $.ajax({         url: "/apiwebservice.asmx/analyticsdatashowwithpost",         type: 'post',         data: formdata,         complete: function(data) {             console.log("successfullly set json!");             getjsonser();         }     }); }  function getjsonser() {     $.ajax({         url: "/apiwebservice.asmx/analyticsdatashowwithpost",         type: 'get',         complete: function(data) {             //alert("this json out  "+json.stringify(data));#             load(data);         }     }); }  function beginload() {     setjsonser(); }  function load(data) {     setjsonser();      var labels = new array();     var values = new array();     var catogories = new array();     var arrayofarray = new array();      var rowdata = "return value of json.stringify(data)"; }  beginload(); 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -