javascript - proper way to fill js variables via ajax request -
at moment using follwing way fill global js variables data obtained json:
var tranlationjson = $.ajax({ type: "get", url: "translation.xml", contenttype: "text/xml", datatype: "xml", success: function (datasource) { tranlationjson=tojasonparser(datasource); } });
is there more clever way? need variables filled because in scrips loaded later use content.
you can make tranlationjson object instead of variable this:
var tranlationjson = { init: function(){ $.ajax({ type: "get", url: "translation.xml", contenttype: "text/xml", datatype: "xml", success: function (datasource) { this.data = tojasonparser(datasource); } }); }
then call init
function this:
tranlationjson.init();
then can access json response data
this:
tranlationjson.data.something;