mercredi 27 mai 2015

Ajax calling WEB API throwing a Parser Error

So I am trying to make an AJAX call to get JSON information from a WEB API. The WEB API method seems to be working properly and when I try to access it via Fiddler, it returns a result:

Fiddler accessing Web API

When I try to access it via JQUERY AJAX, it fails and says that there is a parser error. Below is my AJAX call:

    $.ajax({
            url: 'http://example:port/api/values/',
            type: 'GET',
            dataType: 'jsonp',
            success: function (data) {
                alert("works");
            },
            error: function (request, error) {
                console.log(arguments);
                alert(" Can't do because: " + error);
            }
        });

Below is my WEB API Method:

    [System.Web.Http.HttpGet]
    public List<Users> Get()
    {
        List<Users> user= (from m in new DataAccessLayer.MapRepository().GetUsersRelatingTo("UserName")
                       select new CommonLayer.Views.Markers
                       {
                           ID= m.UserID,

                       }).ToList();
        return users;
    }

I would appreciate any sort of tip, thanks!




Aucun commentaire:

Enregistrer un commentaire