最初の関数を考えてグローバル変数を設定しようとしましたが、たとえば、値を取得しようとするselectedDatesと失敗します。selectedDates['1/23/2013']
$.getの代わりに$.ajaxを試してみると、のような値を取得できますselectedDates['1/23/2013']。
the_selected_datesそれらの両方がセットに返される外部変数を設定する場合の違いはどこにありselectedDatesますか?
var selectedDates = {};
使用する関数$.getは失敗します:
function getSelectedDates_fails(lead_id, month) {
var the_selected_dates = {};
$.get(
window.location.href,
{
gf_lm_ajax : 1,
get : 'lead_reminder_get_dates',
lead_id : lead_id,
month : month,
nonce_gf_lm_ajax : gf_lmJsVars.nonce_gf_lm_ajax
},
function(output) {
$.each(output.reminders, function(n, val) {
the_selected_dates[val.date] = val.date;
});
}, 'json');
return the_selected_dates;
}
selectedDates = getSelectedDates_fails(35, 12); console.debug(selectedDates);
デバッグデータ


作品を使っ$.ajaxた機能:
function getSelectedDates_works(lead_id, month) {
var the_selected_dates = {};
$.ajax(
{
url : window.location.href,
dataType : 'json',
data : {
gf_lm_ajax : 1,
get : 'lead_reminder_get_dates',
lead_id : lead_id,
month : month,
nonce_gf_lm_ajax : gf_lmJsVars.nonce_gf_lm_ajax
},
async : false,
success : function(output)
{
$.each(output.reminders, function(n, val) {
the_selected_dates[val.date] = val.date;
});
}
});
return the_selected_dates;
}
selectedDates = getSelectedDates_works(35, 12); console.debug(selectedDates);
デバッグデータ
