I'm trying to write a javascript/jquery plugin to access a webDav storage with JSON-data only and am struggling to get it to work.
The webDav will be a remote storage, so I need to make a cross-domain ajax request, passing along authentication data.
I have tried various versions, but I'm always failing on the preflight
authentication, while I can access the file correctly, when I enter the URL in the browser directly (and provide login credentials).
This is what I have tried:
$.ajax({
url: priv.url + '/' + priv.user + '/' +
priv.foldertree + '/' + docid,
type: "GET",
async: true,
crossdomain : true,
headers : {
Authorization: 'Basic ' + Base64.encode(
priv.user + ':' + priv.password
)
},
success: function (content) {
console.log( content );
}
});
I have also set the following without luck:
xhrFields: {withCredentials: 'true'}
contentType: 'text/plain'
or:
datatype: "jsonp"
or:
username: priv.user
password: priv.password
or:
beforeSend: function (xhr) {
xhr.setRequestHeader ('Authorization',
"Basic" + Base64.encode( priv.user + ':' + priv.password )
);
}
but all I'm gettin is a 401
authorization failed
response from the remote server on my preflight options
request.
Question:
I don't have access to the remote server, but since it's a remote WebDav Storage-as-a-Service, it should be possible to access the files I'm planning to store there. Can someone give me a pointer on how to correctly make a request to GET my JSON data (I will also need to post, propfind, remove, but first things first...)?
Thanks!