小编ate*_*eet的帖子

发布JSON ajax请求,其中cors无法在IE10/Edge中运行

背景: -我创建了一个托管在本地系统IIS中的WCF服务.服务公开GET/POST方法和跨域启用,也可以使用https访问.要使其可访问,请使用自签名证书.

测试: -当我尝试进行跨域ajax调用时,它适用于IE10/Edge中的GET请求和POST请求(只有那些不接受数据作为json的post方法).我可以在chrome/Firebox浏览器中为任何GET/POST请求进行跨域调用.只有IE 10/Edge会导致在ajax调用中传递contenttype:accept/json参数时对POST请求进行跨域调用的问题.

研究: -我阅读了很多博客/ mdn,并了解了其中IE不虔诚地追随cors的cors规范.我知道cors规范并没有提供自定义标题/标题的值,因为cors preflight已中止.

我正在制作的ajax请求示例: -

var postDT = { "postValue": "test" };
        debugger;
        $.support.cors = true;
        $.ajax({
            type: "POST",
            data: JSON.stringify(postDT),
            url: "http://ateet3371/Service1.svc/postdata",
            contentType: "application/json; charset=utf-8",
            dataType: "JSON",
            processData: true,
            success: function (data) {
                 alert(data);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                var a = jqXHR;
                alert(jqXHR + '---' + textStatus + '---' + errorThrown);
            }
        });
Run Code Online (Sandbox Code Playgroud)

如果我删除contentType: "application/json; charset=utf-8"然后它抛出错误的请求错误,否则它抛出访问被拒绝错误.

WCF中的方法实现是: -

[OperationContract]
    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, …
Run Code Online (Sandbox Code Playgroud)

ajax wcf jquery iis-7.5 cors

14
推荐指数
1
解决办法
2590
查看次数

标签 统计

ajax ×1

cors ×1

iis-7.5 ×1

jquery ×1

wcf ×1