Consume Rest API in C # by Ajax in jquery

0

Hello I have a C # API that returns me an object in JSON Follow the code

[HttpGet]
        public string Login(string Pass, string User)
        {
            Return ret = new Return();
            try
            {
                UsuarioDAL DAL = new UsuarioDAL();
                var Usuario = DAL.ValidarLogin(Pass, User);

                if (Usuario.CPF != null)
                {
                    ret.OK = true;
                    ret.obj = Usuario;
                }
                return JsonConvert.SerializeObject(ret);

            }
            catch (Exception Ex)
            {
                return JsonConvert.SerializeObject(ret);
            }
        }
    }

I made a call in JQUERY using AJAX for this method

    var Login = function (Fn) {
  switch(Fn){
      case 'logar':
          var USER = $('#Name').val();
          var PASS = $('#Pass').val();
          ValidLogin(USER,PASS);
  }
};


function ValidLogin(Us,Ps){
    $.ajax({
        url: 'http://localhost:49982/api/values/Login?Pass=' + Ps + '&User=' + Us + '',
        type: 'GET',
        dataType: 'json'
    }).done(function (data) {
        console.log(data);
    }).fail(function (data) {
        console.log(data);
    });
}
$(document).ready(function () {
    $('#Acesso').click(function () {
        Login('logar');
    });
});

I debug and the url actually calls the API returns the Data in JSON only jquery gives me the error ReferenceError of the date object that I put to display in the console

    
asked by anonymous 28.01.2018 / 21:23

0 answers