0
我使用ajax從服務獲取圖像名稱數組。 當我檢查data.d數組在那裏。但是,我似乎無法將其分配給我的變量,因爲當我提醒它時,它說未定義。從端點獲取圖像
什麼是data.d
只要訪問返回數組?爲什麼.d
?
有沒有更好的方法來做到這一點?我將在程序中稍後介紹一些圖像名稱並循環播放。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.0.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</div>
</form>
<script>
$(function() {
var aryImageNames;
$.ajax({
type: "POST",
url: "Default.aspx/GetImages",
contentType: "application/json; charset=utf-8",
data: "{}",
success: function (data) {
aryImageNames = data.d;
}
});
alert(aryImageNames);
});
</script>
</body>
</html>
但我需要在成功或ajax範圍之外使用數組。我會怎麼做? – Rod
您仍然可以將該數組設置爲全局變量。然後,您可以阻止依賴陣列的區域的使用,直到它被加載(使用成功回調來「激活」/一旦數據加載後顯示該區域)。想象一下像加載屏幕的東西? – Joseph