跨域jQuery Ajax请求和WCF REST服务

我正在调用(Ajax请求)一个WCF REST服务,该请求是一个跨域请求.

如果我在同一个域中部署我的服务,一切都像奶油一样.最终在生产中,该服务将位于不同的域中.

我正在使用jQuery 1.5.2.我的服务给我一个错误说:

errorThrown: "jQuery15208493315000087023_1334089616458 was not called"
textStatus: "parsererror"

虽然在Firefox中我可以看到JSON值,但执行属于Ajax请求的错误处理程序.

我的Ajax请求是:

function CallService() {
    $.ajax({
        type: "GET",url: "http://SomeService/EmpService.svc/GetValues?dv=1455",contentType: "application/json; charset=utf-8",dataType: "jsonp",processdata: false,success: function (data) {
            ServiceSucceeded(data);
        },error: function (jqXHR,textStatus,errorThrown) {
            debugger;
            alert("Service Error");
            ServiceFailed(jqXHR,errorThrown);
        }
    });
}

在WCF服务端,我已将CrossDomainScriptAccess配置为true:

<webHttpBinding>
  <binding name="webHttpBindingWithJsonP"
           crossDomainScriptAccessEnabled="true" />
</webHttpBinding>

我从服务器获得的JSON响应是:

[{"Message": "Stop On Duty","MessageTime": "\/Date(1334068773893-0500)\/"},{"Message": "Start On Duty","MessageTime": "\/Date(1334068763540-0500)\/"},{"Message": "App_testing_4102012924am","MessageTime": "\/Date(1334068533627-0500)\/"},{"Message": "Kunal_testing_4102012924am","MessageTime": "\/Date(1334067945510-0500)\/"},{"Message": "Alert: Door Open","MessageTime": "\/Date(1334066280963-0500)\/"}]

我在设置中遗漏了什么.如果将服务移动到同一域,则整个代码可以正常工作.

我调查了类似的帖子,但无法完成这项工作.

解决方法

好吧,我自己想通了.解决方案是修改包含服务详细信息的配置文件

我在配置文件中添加了标准端点和绑定

<standardEndpoints>
      <webScriptEndpoint>
       <standardEndpoint crossDomainScriptAccessEnabled="true">
       </standardEndpoint>
      </webScriptEndpoint>
      </standardEndpoints>



  <bindings>

  <webHttpBinding>
    <binding name="webHttpBindingWithJsonP"
             crossDomainScriptAccessEnabled="true" />
  </webHttpBinding>

相关文章

1.第一步 设置响应头 header(&#39;Access-Control-Allow...
$.inArray()方法介绍 $.inArray()函数用于在数组中搜索指定的...
jquery.serializejson.min.js的妙用 关于这个jquery.seriali...
JS 将form表单数据快速转化为object对象(json对象) jaymou...
jQuery插件之jquery.spinner数字智能增减插件 参考地址:http...