﻿jQuery(document).ready(function() {

    // Add an item to the list through AJAX.
    $("#addToList").bind("click", function() {
        $.ajax({
            url: "/Service/addToList?userId=" + $("#userId").val() + "&productId=" + $("#productId").val(),
            type: "POST",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            success:
                    function(result) {
                        var obj = JSON.parse(result);
                        if (obj.error) {
                            $("div.product-status")
                                .text(obj.error)
                                .show()
                                .fadeOut(3000);
                            // .remove();
                        } else {
                            $("div.product-status")
                                .text("Successfully added.")
                                .show()
                                .fadeOut(3000);
                            // .remove();
                        }
                    }
        });
    });

});