var ServerTime;
$(function() {
var rand = Math.random();
$.get("getservertime/getime.aspx?radn=" + rand, { Action: "get", Name: "lulu" }, function(data, textStatus) {
this;
ServerTime = data.toString();
})
alert(ServerTime)
});
</script>
怎么才能到到返回值 alert(ServerTime)找不到
var ServerTime;
function GetTime() {
var rand = Math.random();
$.ajax({
type: "get",
url: "getservertime/getime.aspx?radn=" + rand,
datatype: "text",
beforeSend: function(XMLHttpRequest) {
//等待
},
success: function(data) {
ServerTime = data.toString();
},
complete: function(XMLHttpRequest, textStatus) {
},
error: function() {
//请求出错处理
}
});
}
试试看行不行
回调函数里的data应该是一个XMLHttpRequest,你可以写ServerTime = data.responseText试试