JQUERY AJAX - 如何将凭据(用户和密码)传递给 Sharepoint Web 服务

发布于 2024-12-22 00:33:07 字数 805 浏览 3 评论 0原文

当我使用 Internet Explorer 调用任何 Sharepoint Web 服务时,浏览器会要求我提供凭据...但是当我使用 Firefox 或 Chrome 时,我收到“401 未经授权”错误。

我正在编写一个 Firefox 扩展,所以我需要知道如何使用 JQuery 传递凭据......

 $.ajax({
    url: "http://sharepoint.xxxx.com/_vti_bin/search.asmx", 
    type: "POST",
    dataType: "xml",
    data: soapEnv,
    complete: processResult,
    contentType: "text/xml; charset=utf-8"
}); 

    $.ajax({
        url: "http://sharepoint.xxxx.com/_vti_bin/lists.asmx",
        beforeSend: function(xhr) {
            xhr.setRequestHeader("SOAPAction",
            "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
        },
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: processResult,
        contentType: "text/xml; charset=utf-8"
    });

When I call the any of the Sharepoint Webservices using Internet Explorer, the Browser ask me for credentials... but when I'm using Firefox or Chrome I get a "401 Unauthorized" error.

I'm writing a Firefox extension, so I need to know how to pass the credentials using JQuery....

 $.ajax({
    url: "http://sharepoint.xxxx.com/_vti_bin/search.asmx", 
    type: "POST",
    dataType: "xml",
    data: soapEnv,
    complete: processResult,
    contentType: "text/xml; charset=utf-8"
}); 

    $.ajax({
        url: "http://sharepoint.xxxx.com/_vti_bin/lists.asmx",
        beforeSend: function(xhr) {
            xhr.setRequestHeader("SOAPAction",
            "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
        },
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: processResult,
        contentType: "text/xml; charset=utf-8"
    });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2024-12-29 00:33:07

您应该能够使用如下方式传递用户名/密码:

$.ajax({
    url: "http://sharepoint.xxxx.com/_vti_bin/search.asmx", 
    type: "POST",
    xhrFields: {
        withCredentials: true
    },
    dataType: "xml",
    data: soapEnv,
    complete: processResult,
    contentType: "text/xml; charset=utf-8"
    username: username,
    password: password,
    crossDomain: true
});

此调用使用 xhrFields withCredentials: true 并传递用户名和密码,允许您在调用的其余部分中发送这些项目。另外,请注意,crossDomain: true 用于告诉 jQuery 进行任何必要的更改以允许跨域调用。

You should be able to pass username/password by using something like this:

$.ajax({
    url: "http://sharepoint.xxxx.com/_vti_bin/search.asmx", 
    type: "POST",
    xhrFields: {
        withCredentials: true
    },
    dataType: "xml",
    data: soapEnv,
    complete: processResult,
    contentType: "text/xml; charset=utf-8"
    username: username,
    password: password,
    crossDomain: true
});

This call, using the xhrFields withCredentials: true and passing the username and password allow you to send these items with the rest of the call. Also, notice that crossDomain: true is used to tell jQuery to make any necessary changes to allow cross-domain calls.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文