jQueryイベントをDBに保存しようとしています。
//Calling this Function On Click
function trackevent(event){
window.events.push(event)
}
$.each(window.events, function(i, item){
console.log(i +" - "+ $.parseJSON(item));
});
イベントは配列に保存されました。かっこいいですが、ループしようとするとwindow.events
、jQueryイベントのJSONを取り戻すことができません。私は自分の間違いを理解することができません。どんな提案も役に立ちます。
parseJSONをJSON.stringifyに変更した場合、このエラーが発生します
$.each(window.events, function(i, item){
console.log(i +" - "+ JSON.stringify(item));
});
$(document).ready(function(){
window.events = []
// Function to enable the hidden checkbox button
$(".answers_checkbox").click(function(){
current_click = $(this).attr("data-attr");
// If the Hidden checkbox is Checked , it means its already selected (blue)
if($("."+this.id).attr('checked') == 'checked') {
$(this).css('background-image', '');
} else {
// Changing the Background Image to current_click option
$(this).css('background-image',"url('/assets/choice_buttons/choice"+current_click+"_Sq_Blue.png')");
}
$("."+this.id).attr('checked',!$("."+this.id).attr('checked'));
trackevent(event);
});
function trackevent(event){
window.events.push(event)
}
});
// Function to Save Events
$(window).bind('beforeunload', function(){
$.each(window.events, function(i, item){
console.log(i +" - "+ item);
});
});