以下是我的 JavaScript。如何使变量成为success
全局变量,以便在 ajax->success 中所做的更改反映在外部?
function foo() {
var success = false;
$.ajax({
type: "POST",
url: "",
dataType: "xml",
success: function(xml) {
var code = parseInt($(xml).find("Response").attr("code"), 10);
switch (code) {
case 1:
success = false;
break;
case 0:
success = true;
break;
}
}
});
return success;
}