私は、次のJavaScriptを持っている:jQueryの - 変数のスコープ問題
$.getJSON('/calculate_quote/' + moulding_1_id, function(data) {
moulding_1_cost = data.moulding.cost;
moulding_1_width = data.moulding.width;
});
cost_of_moulding = ((2 * (width + (2 * moulding_1_width)) + 2 * (height + (2 * moulding_1_width)))/1000) * moulding_1_cost;
$('#item_total').html(cost_of_moulding);
問題は二つの変数moulding_1_cost
とmoulding_1_width
がgetJSON呼び出しの外で未定義されていることです。 getJSON呼び出しの外部でこれら2つの変数を使用できるようにするにはどうすればよいですか? (サーバはJSONデータで戻ってくるとき)
またはこれ以上^ – slobodan