Ajax json post to Controller across domains, “not allowed by” Access-Control-Allow-Headers

前端 未结 2 1429
梦毁少年i
梦毁少年i 2020-12-03 06:18

I create a simple MVC Controller action, that takes some json data - then return true or false.

    [AllowCrossSiteJson]
    public JsonResult AddPerson(Per         


        
2条回答
  •  情书的邮戳
    2020-12-03 06:40

    To fix the Access-Control-Allow-Origin error, you need to include the following header in your response:

    Access-Control-Allow-Headers: Content-Type

    Basically, any "non-simple" header needs to be included as a comma-delimited list in the header above. Check out the CORS spec for more details:

    http://www.w3.org/TR/cors/

    "Content-Type" needs to be included because "application/json" does not match the values defined here:

    http://www.w3.org/TR/cors/#terminology

提交回复
热议问题