how to bypass Access-Control-Allow-Origin?

前端 未结 6 1928
闹比i
闹比i 2020-11-22 13:55

I\'m doing a ajax call to my own server on a platform which they set prevent these ajax calls (but I need it to fetch the data from my server to display retrieved data from

6条回答
  •  误落风尘
    2020-11-22 14:41

    I have fixed this problem when calling a MVC3 Controller. I added:

    Response.AddHeader("Access-Control-Allow-Origin", "*"); 
    

    before my

    return Json(model, JsonRequestBehavior.AllowGet);
    

    And also my $.ajax was complaining that it does not accept Content-type header in my ajax call, so I commented it out as I know its JSON being passed to the Action.

    Hope that helps.

提交回复
热议问题