首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用.NET DataService和jQuery

使用.NET DataService和jQuery
EN

Stack Overflow用户
提问于 2014-10-01 15:11:42
回答 2查看 115关注 0票数 0

我已经有一些ADO.NET数据服务运行了一段时间,现在我想通过jQuery从web客户端使用它们。当我尝试执行以下操作时,总是调用错误处理程序:

代码语言:javascript
复制
$.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提要响应吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-10-10 06:04:17

下面是对JavaScript的Ajax调用

代码语言: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页面上的服务器端方法。

代码语言:javascript
复制
[WebMethod]
public static string Logout()
{
    HttpContext.Current.Session["User"] = null;
    return "Success";
}

调用wsdl服务时

代码语言:javascript
复制
$.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变量将包含如下代码:

代码语言:javascript
复制
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调用”,将有多个指向这个准确查询的可用链接。

票数 0
EN

Stack Overflow用户

发布于 2014-10-10 05:43:27

您可以尝试使用datajs,它是针对不同OData版本的http://datajs.codeplex.com/的javascript库。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26144590

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档