-2

how i can use the result of this link in variable javascript :

https://aa.real-tv1.com/testtt.php?action=reseller_mapdash1

let url = 'https://aa.real-tv1.com/testtt.php?action=reseller_mapdash1';

var myVariable;

fetch(url).then(res => res.json()).then((out) => {

   myVariable = out;
   
   console.log([myVariable]);
   
}).catch(err => { throw err });

console.log([myVariable]);

so i know where is the problem now , when i use the variable 'myVariable'

outside a function i have Variable undefined

so how i can use the variabla outside a function ?

  • It is not clear what you are asking – ControlAltDel Mar 11 '22 at 13:48
  • *How I can use the result of this link in variable JavaScript* - Give a proper explanation of what the problem with it was. – Debug Diva Mar 11 '22 at 13:49
  • hello , this URL https://aa.real-tv1.com/testtt.php?action=reseller_mapdash1 if you clic on it you see this result : {"code":"MA","value":"1"}, now how i can use this result in js variable, like : var mapData = [{"code":"MA","value":"1"}]; – nabil mouslim Mar 11 '22 at 13:50
  • sxume me im not good in javascript but i need something like this : $aaa = $.getJSON( "https://aa.real-tv1.com/testtt.php?action=reseller_mapdash1"); var myvar = [$aaa]; – nabil mouslim Mar 11 '22 at 14:00

1 Answers1

0

Well, you have done most of the job, you simply assign the result "out" to a variable like so:

let url = 'https://aa.real-tv1.com/testtt.php?action=reseller_mapdash1';
let myVariable;

fetch(url)
    .then(res => res.json())
    .then((out) => {
        myVariable = out; // here you assign to your variable
    })
    .catch(err => { throw err });
mohamedSdn
  • 125
  • 1
  • 10