JQUERY AJAX - 如何将凭据(用户和密码)传递给 Sharepoint Web 服务
当我使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够使用如下方式传递用户名/密码:
此调用使用 xhrFields
withCredentials: true
并传递用户名和密码,允许您在调用的其余部分中发送这些项目。另外,请注意,crossDomain: true
用于告诉 jQuery 进行任何必要的更改以允许跨域调用。You should be able to pass username/password by using something like this:
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 thatcrossDomain: true
is used to tell jQuery to make any necessary changes to allow cross-domain calls.