解决jquery跨域访问

在服务端 web.config添加以下配置


    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Headers" value="Content-Type, api_key, Authorization" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>

 

客户端脚本如下:

  Get

                $.ajax({
                    url: "http://localhost:49302/api/meeting/login/xxx",
                    type: "GET",
                    dataType: "text",
                    success: function (data) {
                        $("#lbl1").text(data);
                        return true;
                    }
                });

 POST

                $.ajax({
                    url: "http://localhost:49302/api/meeting/PostResult/XXXX",
                    type: "POST",
                    dataType: "text",
                    data: { "": "此处为Body的内容" },
                    success: function (data) {
                        $("#lbl1").text(data);
                        return true;
                    }
                });

 

posted on 2015-03-06 10:26  jerron  阅读(163)  评论(0编辑  收藏  举报

导航