weixin_33708432 2011-11-16 21:37 采纳率: 0%
浏览 63

jQuery Ajax WCF跨域

So I have a basic WCF service to be consumed by straight jQuery/HTML, no asp.net.

I can make GET calls to my test.svc/test via the browser and get my expected JSON result. {"d":["test1","test2","test3"]}

Now, I'm trying to consume it via jQuery 1.4.x

$.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        url: methodUrl,
        data: {},
        beforeSend: function (XMLHttpRequest) {
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
        },
        success: successCallback,
        error: failedCallback
    });

I'm grabbing the error info and dumping it to the console, this is my error. LOG: {"readyState":4,"status":0,"statusText":"error"} LOG: "error" LOG: {"message":"Access is denied. ","description":"Access is denied. ","number":-2147024891}

I've read that I need to use JSON-P and/or crossDomainScriptAccessEnabled or 30 other things.

So far I've not seen a consistent solution to this problem.

Any help would be appreciated.

Thanks! Jon

  • 写回答

1条回答 默认 最新

  • weixin_33739541 2011-11-20 23:31
    关注

    So it appears to be a hack for our situation regardless.

    We're using MS Dynamics CRM 2011, which only allows plain html pages with JS and only supports IE.

    We ended up running another WCF service that sits on the same box as CRM (breaking requirements) that is just a proxy that in-turn calls our real WCF service that sits on another box.

    It's goofy and adds more overhead to maintenance but we're at least able to keep producing JSON instead of JSON-P so that other consumers can use it too.

    评论

报告相同问题?

悬赏问题

  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形