ajax call status is 200 but it is not successfull

I working on mvc asp.net project. I call my controller function with ajax, the call status is 200 but it is not successful, and goes to error section.

service:

public async Task<IEnumerable<TeamDto>> GetAllTeamsList()
        {
            var teams = await _teamRepository.GetAll().Include(u => u.Users).ThenInclude(m => m.User).ToListAsync();
            return ObjectMapper.Map<IEnumerable<TeamDto>>(teams);
        }

Controller:

  public  async Task<IEnumerable<TeamDto>> GetTeams()
        {
            var teams = await _teamAppService.GetAllTeamsList();
            return teams;
        }

js file:

  $.ajax(
        {
            type: "GET",
            url: "/App/Team/GetTeams",
            success: function (data) {
        ///
            },
            error: function (data) { console.log("it went bad " + JSON.stringify(data)); }
        });

Error:
TypeError: ‘caller’, ‘callee’, and ‘arguments’ properties may not be accessed on strict mode functions or the arguments objects for calls to them

this is what I get when copy the url in the browser:

{“result”:[{“tenantId”:1,”name”:”admin
team”,”users”:[{“tenantId”:1,”userId”:2,”teamId”:58,”user”:{“profilePictureId”:null,”shouldChangePasswordOnNextLogin”:false,”signInTokenExpireTimeUtc”:null,”signInToken”:null,”googleAuthenticatorKey”:null,”pin”:”1234″,”hourlyRate”:0.00,”payrollId”:””,”warehouseId”:1,”tandaUser”:null,”normalizedUserName”:”ADMIN”,”normalizedEmailAddress”:”[email protected]“,”concurrencyStamp”:”bd7ee91e-587b-4ae2-bc97-be2ce7d7789b”,”tokens”:null,”deleterUser”:null,”creatorUser”:null,”lastModifierUser”:null,”authenticationSource”:null,”userName”:”admin”,”tenantId”:1,”emailAddress”:”[email protected]“,”name”:”admin”,”surname”:”admin”,”fullName”:”admin
admin”,”password”:”AQAAAAEAACcQAAAAENfcSE+zBppFKVxKUynGBiy4WZgDU3C3gbbWnQUdEyBb5J/S0uLkcqk+2MwM0DXxjw==”,”emailConfirmationCode”:null,”passwordResetCode”:null,”lockoutEndDateUtc”:null,”accessFailedCount”:1,”isLockoutEnabled”:true,”phoneNumber”:””,”isPhoneNumberConfirmed”:false,”securityStamp”:”07a4d582-7233-3fbc-f3f7-39f015ee388b”,”isTwoFactorEnabled”:false,”logins”:null,”roles”:null,”claims”:null,”permissions”:null,”settings”:null,”isEmailConfirmed”:true,”isActive”:true,”isDeleted”:false,”deleterUserId”:null,”deletionTime”:null,”lastModificationTime”:”2020-09-30T02:54:34.402372Z”,”lastModifierUserId”:null,”creationTime”:”2019-09-05T23:27:47.8514365Z”,”creatorUserId”:null,”id”:2},”team”:{“tenantId”:1,”name”:”admin
team”,”users”:[

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Open up the developer tools and look at the URL it is trying to request. Normally in the context of the application, you don’t have the /App defined. In fact, you can use ASP.NET MVC Url helper to get the action method, to make sure the path is correct:

$.ajax({
    type: "GET",
    url: "@Url.Action("GetTeams", "Team")",

Also, normally you would return data via JSON from the controller like:

  public  async Task<IEnumerable<TeamDto>> GetTeams()
  {
      var teams = await _teamAppService.GetAllTeamsList();
      return Json(teams, JsonRequestBehavior.AllowGet);
  }

And maybe that would make a difference, using Json() from the asp.net mvc controller. Note AllowGet ensures that GET requests on an action returning JSON works, otherwise it will be blocked and return an error.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x