I used two projects for my site. One for the Mvc project and the Api project. I added the code below in the web.config file, which is in the Api project,
Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, POST, PUT, DELETE Access-Control-Allow-Headers: Authorization
The action method below in the Api project,
[HttpPost] [Route("api/ajaxapi/caselistmethod")] public List<CaseValues> AjaxCaseListMethod() { List<CaseValues> caseList = new List<CaseValues>(); return caseList; }
and ajax, as shown below, in the Mvc project,
$.ajax({ type: "POST", url: "http://localhost:55016/api/ajaxapi/caselistmethod", beforeSend: function (request) { request.setRequestHeader("Authorization", getCookie("Token")); }, success: function (response) { } });
But showing errors as shown below
OPTIONS http: // localhost: 55016 / api / ajaxapi / caselistmethod 405 (method not allowed) XMLHttpRequest cannot load http: // localhost: 55016 / api / ajaxapi / caselistmethod . Preflight response has an invalid HTTP status code 405
but without a title its working tone. I also need to pass the header. Therefore, please give any suggestion.
Thanks...
source share