【发布时间】:2014-06-04 07:34:02
【问题描述】:
我想在工作中为我的 SharePoint 服务器制作一个简单的 CRUD 跨平台移动应用程序。我正在使用 PhoneGap 来处理跨平台编码 - 因此我的代码将使用 HTML、CSS 和 JavaScript。
我遇到的主要障碍是使用我的 SharePoint 服务器进行身份验证。许多在线用户已成功使用 AJAX 调用,但是我收到以下错误:
XMLHttpRequest cannot load http://<DOMAIN>/_vti_bin/authentication.asmx. The request was redirected to 'http://<DOMAIN>/_layouts/15/error.aspx?ErrorText=Request%20format%20is%20unrecognized%2E', which is disallowed for cross-origin requests that require preflight.
以下是我的 JavaScript 代码:
function Authenticate() {
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
$("#topnavcontent").append("Creating SOAP envelope...</br>");
var soapEnv = "<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>" +
"<Login xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">" +
"<username>USERNAME</username>" +
"<password>PASSWORD</password>" +
"</Login>" +
"</soap:Body>" +
"</soap:Envelope>";
$("#topnavcontent").append("Calling authenticate.asmx...</br>");
$.ajax({
url: "http://<DOMAIN>/_vti_bin/authentication.asmx",
type: "POST",
data: soapEnv,
complete: authenticationResultSuccess,
contentType: "text/xml; charset=\"utf-8\"",
error: authenticationResultError
});
}
我了解浏览器正在发送飞行前 OPTIONS 调用。 SharePoint 网站默认不支持 OPTIONS 调用。是否有任何解决方法,例如禁用此 OPTIONS 调用或 SharePoint 网站上的 webconfig 中允许飞行前通过的设置。提前感谢您的帮助。
【问题讨论】:
-
您是否在您的 config.xml 中为 phonegap 项目设置了
<access origin="*" />? -
愚蠢的问题,但是您的 Sharepoint 服务器是否接受跨域请求?
-
@AymKdn SharePoint 网站的“Access-Control-Allow-Origin”设置为“*”。
-
@Dawson
<access origin="*" />已经是 config.xml 的一部分。
标签: javascript android sharepoint cordova