I have the following code inside a button-click-function
var ItemID2;
$.get("http://localhost/tddd27/index.php/json/Products?ItemName="+thisID,
function(data){
ItemID2=data[0].ItemID;
},"json");
console.log(ItemID2);
after I click the button I see in the console that ItemID2
is undefined. If I use console.log(data[0].ItemID)
inside the get-function I see the correct value. I think that the problem is that the execution of the function continues but Ajax has not yet retrieve the value of ItemID2
. Any idea how can I fix that?