weixin_33716557 2016-05-13 05:58 采纳率: 0%
浏览 72

我该如何解决这个错误

I am trying to call WCF Services using AJAX, below is my code:

$.ajax({
    url: "http://localhost/TestingServices/Service1.svc/GetData"
    data: "{'value:1}",
    type: "POST",
    dataType: "json",
    contentType: "application/json; charset=utf-8",
    success: function(data) {
        alert(data);
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
        alert(textStatus);
    }
});

But after execution it gives me following error:

XMLHttpRequest cannot load 
  http://localhost/TestingServices/Service1.svc/GetData.Response to 
  preflight request doesn't pass access control check: 
  No 'Access-Control-Allow-Origin' header is present on 
  the requested resource. Origin 'null' is therefore not 
  allowed access. The response had HTTP status code 404.

Can anyone help me how to resolve this ?

  • 写回答

2条回答 默认 最新

  • weixin_33704234 2016-05-13 06:22
    关注

    Try 2 Add HttpProtocols in web.config of your service project

        <system.webServer>
        <httpProtocol>
          <customHeaders>
            <add name="Access-Control-Allow-Origin" value="*" />
            <add name="Access-Control-Allow-Headers" value="Content-Type" />
            <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
          </customHeaders>
        </httpProtocol>
    </system.webServer>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程