使用jQuery使用.NET数据服务
我已经有一些ADO.NET数据服务运行了一段时间,现在想通过jQuery从web客户端使用它们。当我尝试执行以下操作时,始终会调用错误处理程序:使用jQuery使用.NET数据服务,jquery,wcf-data-services,Jquery,Wcf Data Services,我已经有一些ADO.NET数据服务运行了一段时间,现在想通过jQuery从web客户端使用它们。当我尝试执行以下操作时,始终会调用错误处理程序: $.ajax( { type: "GET", url: "Service.svc/Customers()", contentType: "application/atom+xml;type=feed;charset=utf-8", dataType: "xml",
$.ajax(
{
type: "GET",
url: "Service.svc/Customers()",
contentType: "application/atom+xml;type=feed;charset=utf-8",
dataType: "xml",
xhrFields: { withCredentials: true },
error: function (jqXHR, textStatus, errorThrown) { alert(jqXHR.response + textStatus + errorThrown); },
success: function (xml) { alert(xml); }
}
);
观察fiddler,数据以XML格式正确返回,但始终调用错误处理程序。jQuery不能解析应用程序/atom+xml提要响应吗?您可以尝试使用datajs,这是一个针对不同OData版本的javascript库
$.ajax({
url: "Login.aspx/Logout",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (o) {
window.location.href = "Login.aspx";
},
error: function (o) {
logoutSession();
}
});
任何aspx页面上的服务器端方法
[WebMethod]
public static string Logout()
{
HttpContext.Current.Session["User"] = null;
return "Success";
}
调用wsdl服务时
$.ajax({
url: "Service.svc/Customers",
type: "POST",
dataType: "xml",
data: soapMessage,
processData: false,
contentType: "text/xml; charset=\"utf-8\"",
success: function (xml) { alert(xml); },
error: function (jqXHR, textStatus, errorThrown) { alert(jqXHR.response + textStatus + errorThrown); }
});
soapMessage
变量将包含如下代码:
var soapMessage =
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">\
<soap:Body> \
<SaveProduct xmlns="http://sh.inobido.com/"> \
<productID>' + productID + '</productID> \
<productName>' + productName + '</productName> \
<manufactureDate>' + manufactureDate + '</manufactureDate> \
</SaveProduct> \
</soap:Body> \
</soap:Envelope>';
var soapMessage=
'\
\
\
“+productID+”\
“+productName+”\
“+制造日期+”\
\
\
';
来源
上面的源代码为您提供了一步一步的指导,如果源代码不起作用,谷歌“如何从ajax进行soap调用”,将有多个指向此确切查询的可用链接还可以使用
SoapUI
获取要发送到服务器的正确XML正文,SoapUI
是测试web服务和其他与soap相关的东西的好工具