flot javascript 라이브러리를 사용하여 그래프를 만듭니다. 클릭 가능한 이벤트를 사용하도록 설정하고 div가 plotclick 이벤트에 바인딩됩니다. 따라서 데이터 포인트를 클릭하면 아약스 호출이 만들어지고 그 결과가 현재 div를 대체하는 데 사용됩니다. 이 후에 div를 새 이벤트에 바인딩해야합니다.jquery에서 ajax 호출 후 다른 이벤트에 바인딩하는 방법
bind를 호출하려고했지만 여전히 이전 콜백에 바인딩되어 있습니다. 바인딩 해제 및 바인드를 호출하면 새 콜백이 호출되지 않습니다.
var handleTeacherClick = function(event, pos, item) {
if(typeof item != "undefined" && item) {
var user_id = jQuery('input[name="id' + item.datapoint[0] + '"]').val();
jQuery.ajax({
type: 'POST',
url: BASEPATH + 'index.php/ajax/home/latest',
data: { "user_id": user_id },
dataType: 'json',
success: function (result) {
jQuery.plot(jQuery('#stats_prog'),
result.progress_data, result.progress_options);
jQuery.plot(jQuery('#stats_perf'),
result.performance_data, result.performance_options);
jQuery('.stats_title').
html('<span class="stats_title">'+
' >> Chapter '+Math.ceil(item.datapoint[0])+'</span>');
jQuery('#stats_prog')./*unbind("plotclick").*/
bind('plotclick', statClickHandler);
jQuery('#stats_perf')./*unbind("plotclick"). */
bind('plotclick', statClickHandler);
},
});
}
}