Subversion Repositories bacoAlunos

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

function rest(restAction,serviceName,data,webMessagesContainer,handlerOk,handlerFail)
{
    var request =
    {
        data : data,
        service : serviceName
    }

    $.ajax({
        url: restAction,
        type: "POST",
        contentType: "application/json",
        data: request,
        dataType: "json",

        success: function(resposta)
        {

            $(webMessagesContainer).find(".web-messages").html("");
            if(resposta.service == "error")
            {
                $(webMessagesContainer).find(".web-messages").html('<div class="alert alert-danger">' + resposta.exception + '</div>');
                if(handlerFail != undefined)
                {
                    handlerFail(resposta.exception);
                }

            }
            else if(resposta.service == "ok")
            {
                for(var msg in resposta.messages)
                {
                    $(webMessagesContainer).find(".web-messages").append('<div class="alert alert-success">' + resposta.messages[msg] + '</div>');
                }
                if(handlerOk != undefined)
                    handlerOk(resposta.response);
            }
        },
        error: function(resposta) {
            $(webMessagesContainer).find(".web-messages").html('<div class="alert alert-danger">Erro de comunicação, por favor tente novamente</div>');
            if(handlerFail != undefined)
            {
                handlerFail(resposta.exception);
            }
        }
    });
}