我创建了一个启用了WCF ajax的Web服务,名为“ Service1.svc”
“我必须使用Jquery在另一个应用程序中调用此服务。”
我已经在其中创建了方法:
[OperationContract]
public string GetMarkup()
{
string data = "<div>My HTML markup text here</div>";
return data;
}
现在,我在第二个应用程序的html页面中创建了jquery脚本:
var markup = "";
$.ajax({
type: "POST",
url: "http://localhost:1676/MyWCFService.svc/GetMarkup",
contentType: "application/json",
data: "{}",
dataType: "json",
success: callback,
error: function (textStatus) {
alert("ERROR");
}
});
function callback(result) {
alert("Inside Callback");
markup = result.d;
$("#divMyMarkup").html(markup);
alert(markup);
}
现在,我的问题是,每当我在IE中执行此页面时,它都可以正常工作。
但是在Firefox中,它无法正常工作。它给出警报错误消息,该消息在
在上面的ajax调用中
error: function (textStatus) {alert("ERROR");}
。我使用$ .get(),$(“#divMyMarkup”)。load(serviceUrl,callback)尝试了此功能。
我也尝试通过将数据类型更改为json,jsonp,html来尝试此操作。
我仍然没有得到确切的解决方案。
这里有专家吗?
最佳答案
在另一个应用程序中使用Jquery
根据我的经验,IE不会尊重跨域策略,而是让您拨打电话,而不是参考...
找出答案的唯一方法是让html页面/ JQuery脚本从Firefox上的http://localhost:1676/ICallWcfServicesWithJQuery.html
调用WCF服务。
可能的解决方案:
[JSONP] how to avoid cross domain policy in jquery ajax for consuming wcf service?
[flXHR] [php-proxy] jQuery “getJSON” from an external domain that doesn't support JSON-P output
[JSONP] Accessing web Service from jQuery - cross domain
[.net-proxy] aspnet-proxy-page-cross-domain-requests-from-ajax-and-javascript
在多种浏览器上进行测试,添加1盎司杜松子酒,一罐滋补品,您会很好!