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

时间:2011-12-17 05:49:27

标签: jquery web-services internet-explorer sharepoint firefox-addon

当我使用Internet Explorer调用任何Sharepoint Webservices时,浏览器会询问我的凭据......但是当我使用Firefox或Chrome时,我收到“401 Unauthorized”错误。

我正在编写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"
    });

1 个答案:

答案 0 :(得分:-1)

您应该可以使用以下内容传递用户名/密码:

$.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进行必要的更改以允许跨域调用。

相关问题