jQuery的成功赋值

I have a url that returns some text. I would assign this string to the region variable. How can I do it?

var region="";
$.get("retrieve/region", function(data) {
    region=data;
    alert(data);
});

alert("r= "+region);

The function defined inside the $.get() call won't run right away, so your alert prints the value of region before the $.get() callback has assigned it a value. If you put the alert inside of the function, so that it ran after the value was assigned, you would see that your code does indeed work (jsfiddle).