src/main/webapp/scripts/main.js
/**
     * API Change Favorite Item
     * @param evt
     */
API Change Favorite Item
@param evt
API Change Favorite Item @param evt
function changeFavoriteItem(evt) {
        var tar = evt.target,
            oParent = tar.parentElement;
        if (oParent && oParent.className === 'fav-link') {
            console.log('change ...')
            var oCurLi = oParent.parentElement,
                classname = tar.className,
                isFavorite = classname === 'fa fa-heart' ? true : false,
                oItems = oItemList.getElementsByClassName('item'),
                index = Array.prototype.indexOf.call(oItems, oCurLi),
                url = './history',
                req = {
                    user_id: userId,
                    favorite: itemArr[index]
                };
            var method = !isFavorite ? 'POST' : 'DELETE';
            ajax({
                method: method,
                url: url,
                data: req,
                success: function (res) {
                    if (res.status === 'OK' || res.result === 'SUCCESS') {
                        tar.className = !isFavorite ? 'fa fa-heart' : 'fa fa-heart-o';
                    } else {
                        throw new Error('Change Favorite failed!')
                    }
                },
                error: function () {
                    throw new Error('Change Favorite failed!')
                }
            })
        }
    }
function changeFavoriteItem ( evt ) { var tar = evt . target , oParent = tar . parentElement ; if ( oParent && oParent . className === 'fav-link' ) { console . log ( 'change ...' ) var oCurLi = oParent . parentElement , classname = tar . className , isFavorite = classname === 'fa fa-heart' ? true : false , oItems = oItemList . getElementsByClassName ( 'item' ) , index = Array . prototype . indexOf . call ( oItems , oCurLi ) , url = './history' , req = { user_id : userId , favorite : itemArr [ index ] } ; var method = ! isFavorite ? 'POST' : 'DELETE' ; ajax ( { method : method , url : url , data : req , success : function ( res ) { if ( res . status === 'OK' || res . result === 'SUCCESS' ) { tar . className = ! isFavorite ? 'fa fa-heart' : 'fa fa-heart-o' ; } else { throw new Error ( 'Change Favorite failed!' ) } } , error : function ( ) { throw new Error ( 'Change Favorite failed!' ) } } ) } }
API Change Favorite Item
 @param evt
API Change Favorite Item @param evt