﻿

function WebService(url,callback,pars,callBackError){
    if(typeof(pars)=='function'){
        callBackError = pars;
        pars =
        '';
    }
    $.ajax({
        data:pars,
        url: url,
        type: "POST",
        contentType:"application/json; charset=utf-8",
        dataType:'json',
        cache:false,
        success:function(json){
            callback(json);
        },
        error:function(xml,status){
            if(status=='error'){
                try{
                var json = eval('(' + xml.responseText + ')');
                alert(json.Message,alertType.erro);
                if (callBackError){
                    callBackError();
                }
            }
            catch(e){}
        }
        else{
            alert(status,alertType.erro);

        }

        },
            beforeSend:
            function(xml){
                if(!this.data)
                    xml.setRequestHeader("Content-Type", "application/json;utf-8");
        }

    });

}

(function($){


	$.extend({
		ws: function(url,callback,pars,callBackError) {
			if(typeof(pars)=='function'){
                callBackError = pars;
                pars =
                '';
            }
            $.ajax({
                data:pars,
                url: url,
                type: "POST",
                contentType:"application/json; charset=utf-8",
                dataType:'json',
                cache:false,
                success:function(json){
                    callback(json);
                },
                error:function(xml,status){
                    if(status=='error'){
                        try{
                        var json = eval('(' + xml.responseText + ')');
                        alert(json.Message,alertType.erro);
                        if (callBackError){
                            callBackError();
                        }
                    }
                    catch(e){}
                }
                else{
                    alert(status,alertType.erro);

                }

                },
                    beforeSend:
                    function(xml){
                        if(!this.data)
                            xml.setRequestHeader("Content-Type", "application/json;utf-8");
                }

            });

		}
	});
})(jQuery);