尽我所能,我无法使用全局变量在函数之外获取数据。我已经尝试了所有我能想到的方法,包括 window.nuTime 但没有成功。
$.ajax({
cache: false,
type: 'POST',
url: 'servertime.asp',
data: {},
success: function (data) {
$('#servertime').html(data);
window.nuTime = data;
//alert(data);
},
error: function (jxhr, msg, err) {
$('#response').append('<li style="color:red">' + msg + '</li>');
}
});
alert(nuTime);
最佳答案
科林克是对的!您可以像这样改进此操作:
$.ajax({
cache: false,
type: 'POST',
url: 'servertime.asp',
data: {},
success: function (data) {
$('#servertime').html(data);
alertNuTime(data);
},
error: function (jxhr, msg, err) {
$('#response').append('<li style="color:red">' + msg + '</li>');
}
});
function alertNuTime(data) {
alert(data);
}
关于jquery - 在函数外部声明全局变量时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14116718/