使用AJAX jQuery调用WCF(3.5)
我无法让对另一台服务器的ajax调用正常工作。它在本地工作,如果我使用c代码或使用soapui之类的程序,它就可以工作,所以我想我的浏览器正在“阻止”调用。下面的wsdata包含一个soap信封。错误消息是“400错误请求”。有什么想法吗 我无法使用下面的web.config设置,因为它不受支持使用AJAX jQuery调用WCF(3.5),jquery,ajax,wcf,Jquery,Ajax,Wcf,我无法让对另一台服务器的ajax调用正常工作。它在本地工作,如果我使用c代码或使用soapui之类的程序,它就可以工作,所以我想我的浏览器正在“阻止”调用。下面的wsdata包含一个soap信封。错误消息是“400错误请求”。有什么想法吗 我无法使用下面的web.config设置,因为它不受支持 <system.serviceModel> <bindings> <webHttpBinding> <binding nam
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true"/>
</webHttpBinding>
</bindings>
</system.serviceModel>
function invokeService() {
$(document).ready(function() {
$.ajax({
type: "GET",
//async: "false",
url: "service.svc",
data: wsdata,
contentType: "application/soap+xml; charset=utf-8",
dataType: "xml",
//processData: true,
success: function(result) {
AjaxSucceeded(result);
},
error: AjaxFailed
});
});
}
function AjaxSucceeded(result) {
alert(result);
}
function AjaxFailed(result) {
alert(result.status + ' ' + result.statusText);
}
将您的数据类型设置为jsonp,因为您正在设置
webHttpBindingWithJsonP
,并确保从服务传递json响应
dataType: 'jsonp'
我没有使用webHttpBindingWithJsonP,这只是一个示例。还有其他想法吗?更正:ajax调用中的类型是POST。
dataType: 'jsonp'