title: JSON return value to global variable
body: <p>Simply my code looks like this:</p>
  
  <pre><code> var thevariable = 0;
  
  For(){
  //somecode using thevariable
  $.getJSON('',{},function(e){
  //success and i want to set the returned value from php to my variable to use it in the forloop
  
  thevariable = e.result;
  });
  }
  </code></pre>
  
  <p>my main problem that the variable value stays "0", during the whole For loop, while i only want it to be "0" at the first loop, then it takes the result returned from PHP to use it on for loop.</p>
  
  <p>here it my real code if you need to take a look:</p>
  
  <pre><code>var orderinvoice = 0;
  for(var i=0; i&lt;table.rows.length; i++){
                              var ordername = table.rows[i].cells[5].innerText;
                              var orderqty = ((table.rows[i].cells[1].innerText).replace(/\,/g,'')).replace(/Qty /g,'');
                              var orderprice = (table.rows[i].cells[2].innerText).replace(/\$/g,'');
                              var ordertype = table.rows[i].cells[3].innerText;
                              var orderlink = table.rows[i].cells[4].innerText;
  
        $.getJSON('orderprocess.php', {'invoice': orderinvoice, 'pay_email': email, 'ord_name': ordername, 'ord_qty': orderqty, 'ord_price': orderprice, 'ord_type': ordertype, 'ord_link': orderlink}, function(e) {
            console.log();
            document.getElementById("result").innerText= document.getElementById("result").innerText + "Order #"+e.result+" Created Successfully ";
           document.getElementById("invoker").innerText = ""+e.invoice;
           orderinvoice = e.invoice;
  
            if(i+1 == table.rows.length){
              document.getElementById("result").innerText= document.getElementById("result").innerText + "With invoice #" + e.invoice;
            }
   });
  </code></pre>