var APPLICATION_DOMAIN = '/';

function post(url, data) {
    var response;

    $.ajax({
        url : APPLICATION_DOMAIN + url,
        type : "POST",
        dataType : "json",
        data : data,
        async : false,
        cache : false,
        error: function(){
            alert('通信に失敗しました。CTRL+F5キーでページを更新後に再度操作を行ってみてください。');
        },
        success : function (data) {
            $.each(data, function(key, value) {

                switch(key) {
                    case 'error':
                        alert(value);
                        break;

                    case 'redirect':
                        location.href=value;
                        break;

                    case 'response':
                        response = value;
                        break;
                }
            });
        }
    });

    return response;
}

function PostToOpinionBox() {

    user_opinion = $("#comment").val();

    if (user_opinion) {

        // Post値の設定
        url = 'opinionbox/post';
        data = {
            "comment" : user_opinion
        }

        // 更新
        response = post(url, data);
        if (response) {
            $('#opinion_box').html(response);
        }

    }

}
