当我使用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"
});
答案 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进行必要的更改以允许跨域调用。