Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

mvc webapi with jquery ajax

I have super simple webapi call. and when I use aspx/c#, everything is working.
so I try to use ajax jquery to call. and I always get error, but it does not tell me the error.

I also test it with postman using get or post method. They are still working on postman.
so I guess what I need to do with the code below when postman is working....


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
     <script type="text/javascript">                  
               
         function GetFleetList()
         {
            $.ajax({
               type: "GET",
               url: "https://www.test.com/api/api/Fleet/GetFleetListTestGet?type=json",                            
               dataType: "json",
               contentType: "application/json;charset=utf-8",
               success: function ()
                {
                            alert("Success")
                },
                error: function (request, message, error)
                {
                              alert("Error" + error + " " + message + " " );
                }
           });
         }
    </script>

Open in new window



[HttpGet]
        [Route("api/Fleet/GetFleetListTestGet")]
        public List<Domain.Fleet> GetFleetListTestGet()
        {
            #region mapping parms
            _fleet.FleetMasterType = "Tow";
            #endregion
            return _masterFleet.GetFleetList(_fleet);
        }

Open in new window

SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial