Ik heb een gewone html pagina die met jquery een web api aanroept. Eigenlijk allemaal redelijk simpel
in mijn MVC project
CORS is enabled
Als ik de html pagina open, krijg ik in Chrome:
In IE11 krijg ik in de console
Maar als ik dan op de link klik, manueel invoer of via Fiddler krijg ik wel het antwoord op mijn request
Ik weet dat het waarschijnlijk een enorm dwaas probleem zal zijn. Het zijn enkel maar van die domme dingen die mij overkomen
Maar ik geraak er echt niet uit.
JavaScript:
1
2
3
4
5
6
7
8
9
10
11
| $.ajax({ url: "http://HV.local/api/ws_HV_Attesten/Get", type: "GET", crossDomain: true, contentType: "application/json; charset=utf-8", dataType: 'json', success: function(data) {...}, error: function (error) { alert("Error: " + error.Error); } }); |
in mijn MVC project
C#:
1
2
3
4
5
6
7
8
9
| public class ws_HV_AttestenController : ApiController { [System.Web.Http.AcceptVerbs("GET")] [System.Web.Http.HttpGet] public string Get() { return "gelukt"; } } |
CORS is enabled
C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| public static class WebApiConfig { public static void Register(HttpConfiguration config) { var cors = new EnableCorsAttribute("*", "*", "*"); config.EnableCors(cors); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { controller = "ws", action = "Index", id = RouteParameter.Optional } ); } } |
Als ik de html pagina open, krijg ik in Chrome:
code:
1
2
| Failed to load resource: the server responded with a status of 404 (Not Found) XMLHttpRequest cannot load http://HV.local/api/ws_HV_Attesten/Get/. Invalid HTTP status code 404 |
In IE11 krijg ik in de console
code:
1
| SCRIPT7002: XMLHttpRequest: Netwerkfout 0x80070005, Toegang geweigerd. |
Maar als ik dan op de link klik, manueel invoer of via Fiddler krijg ik wel het antwoord op mijn request
code:
1
| <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">gelukt</string> |
Ik weet dat het waarschijnlijk een enorm dwaas probleem zal zijn. Het zijn enkel maar van die domme dingen die mij overkomen
2x Marstek Venus E 5.12 v153 - CT003 V117 - BMS 212 en 215