嗨,大家好^有這樣的代碼:瓦爾未定義
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
var array = [];
$.get("http://wisepla3nt.com/331.txt",
function(data) {
array = data.split(/\r\n|\r|\n/)
}
);
</script>
<script>alert(array[Math.floor(Math.random()*array.length)]);</script>
</body>
</html>
在警報已經不確定的。爲什麼?數組是全局的。
可能重複[如何返回從AJAX調用的響應?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-呼叫) – adeneo