
function serRequestHeader(xhr) {
    var token = $('meta[name="csrf_token"]').attr('content');
    if (token) return xhr.setRequestHeader('X-XSRF-TOKEN', token);
}

function deleteItem(type, id) {
    var element = $("#"+type+"-"+id);

    $.ajax({
        url: host+"/"+type+"/"+id,
        type: "DELETE",
        data: { _token: $('meta[name="csrf_token"]').attr('content') },
        dataType: "json",
        beforeSend: function(xhr) {
            element.find(".ui.button").addClass('disabled');
        }
    }).done(function(r){
        if( r ) {
            $(".ui.message").html("<b>刪除成功</b>").slideDown();
            element.remove();
        } else {
            $(".ui.message").html("<b>刪除失敗</b>").slideDown();
            element.find("btn").removeClass('disabled');
        }
        hideMessage();
    });
}