我已经有一些ADO.NET数据服务运行了一段时间,现在我想通过jQuery从web客户端使用它们。当我尝试执行以下操作时,总是调用错误处理程序:
$.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); }
}
);看着小提琴,数据正确地以XML格式返回,但是错误处理程序总是被调用。jQuery不能解析应用程序/原子+xml提要响应吗?
发布于 2014-10-10 06:04:17
下面是对JavaScript的Ajax调用
$.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>';源http://openlandscape.net/2009/09/25/call-soap-xm-web-services-with-jquery-ajax/
上面的源代码给您一步一步的指导,如果源不工作,Google“如何从ajax执行soap调用”,将有多个指向这个准确查询的可用链接。
发布于 2014-10-10 05:43:27
您可以尝试使用datajs,它是针对不同OData版本的http://datajs.codeplex.com/的javascript库。
https://stackoverflow.com/questions/26144590
复制相似问题