我想在我的ajax響應中訪問變量「維度」,但無法獲取它。我不想讓這個變量全局。以下是我的代碼
javascript中的範圍變量,jquery
$(document).ready(function(){
$('#submittext').click(function(){
var dimensions;
$.ajax({
type: "GET",
url: "bin/getcontentsize.php",
data: findContentsize,
success: function(response){
//want to access dimensions here to assign response and some calculation(but not able to access it)
}
});
//so i can use here
});
});
你是什麼意思,你不能訪問它?它會產生一個錯誤,錯誤的值等... – JaredPar
你應該可以很好地訪問尺寸。然而,它將會是'未定義'的,因爲你從未初始化它。 – samjudson
@samjudson是的,它說沒有定義 –