?Briella 2015-05-30 08:03 采纳率: 0%
浏览 281

如何启用CORS?

I'm making a request from client side to a web-API on different domain to extract data in JSON format. How do I enable Cross Origin Resource Sharing(CORS)? Client runs on https while my web-API runs on http.

This is the AJAX call that I'm making :

$(document).ready(function () {
    $.ajax({
        type: "GET",
        url: "http://map.techriff.in/api/values",
        success: function (json) {
            console.log(json);
        },
        error: function (err) {
            console.log(err);
        }
    });
});
  • 写回答

4条回答 默认 最新

  • weixin_33695450 2015-05-30 22:52
    关注

    You need to add the Access-Control-Allow-Origin: http://domain.com to your response header, where domain.com is replaced with the domain you want to allow (don't use * wildcards).

    How you do this depends one your server stack. In ASP.NET:

    Response.AppendHeader("Access-Control-Allow-Origin", "http://domain.com");
    

    You then need to set $.support.cors = true in your jQuery to enable it on the client.

    评论

报告相同问题?

悬赏问题

  • ¥15 Coze智能助手搭建过程中的问题请教
  • ¥15 12864只亮屏 不显示汉字
  • ¥20 三极管1000倍放大电路
  • ¥15 vscode报错如何解决
  • ¥15 前端vue CryptoJS Aes CBC加密后端java解密
  • ¥15 python随机森林对两个excel表格读取,shap报错
  • ¥15 基于STM32心率血氧监测(OLED显示)相关代码运行成功后烧录成功OLED显示屏不显示的原因是什么
  • ¥100 X轴为分离变量(因子变量),如何控制X轴每个分类变量的长度。
  • ¥30 求给定范围的全体素数p的(p-2)/p的连乘积值
  • ¥15 VFP如何使用阿里TTS实现文字转语音?