I have a bit of code that uses JSON to check vat numbers.
I need to know which VAT numbers are correct
BTW[0] = 'NL1234567890';
BTW[1] = 'NL1233537891';
BTW[2] = 'NL1232346894';
var arraylength = BTW.length;
for (var i = 0; i < arraylength; i++) {
var BTWnummer = BTW[i];
callUrl = 'http://isvat.appspot.com/'+Land+'/'+BTWnummer+'/?callback=?';
$.getJSON(callUrl, BTWnummer, function(data){
alert(data+' '+BTWnummer);
});
}
The data variable returns true or false. But I can't get the right BTWnummer inside the function that returns from the JSON. It always keeps 1 BTW number. I think JSON is asynchronous, so how can I get the right number inside the bit of JSON code? According to my tests It does use the different numbers in the callUrl.
See Question&Answers more detail:os