Your alert is executing before the Ajax request is finished. Try the following.
var foo = "";
$.ajax({
url: "/",
dataType: "text",
success: function(response) {
foo = "New value:" + response;
alert(foo);
},
error: function() {
alert('There was a problem with the request.');
}
});