Commit 8a995ab9 authored by Siddhant Sanyam's avatar Siddhant Sanyam

Added/Edited saveXHR and loadXHR with $.ajax

Just specify the test document URL at one place: theme.html
Specify the authorization credentials in tools.js:saveXHR
parent 4cf62395
......@@ -37,41 +37,19 @@ currentTime = function() {return (new Date()).toUTCString();}
// save
saveXHR = function(address) {
//create request
var xhr=null;
try
{
xhr = new XMLHttpRequest();
} catch(e)
{
try {xhr = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e2)
{
try {xhr = new ActiveXObject("Microsoft.XMLHTTP");}
catch (e) {alert("Please install a more recent browser")}
}
}
//xhr.open("PUT", keyToUrl(key, wallet), true, wallet.userAddress, wallet.davToken);
//HACK:
xhr.open("PUT", address, true);
xhr.setRequestHeader("Authorization", "Basic "+"nom:test");
//END HACK.
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
if(xhr.status != 200 && xhr.status != 201 && xhr.status != 204) {
alert("error: got status "+xhr.status+" when doing basic auth PUT on url "+Base64.encode("nom:test")+" " + xhr.statusText);
}
}
}
xhr.withCredentials = "true";
xhr.send(JSON.stringify(getCurrentDocument()));
}
alert("Saving"+address);
$.ajax({
url: address,
type: "PUT",
headers: {Authorization: "Basic "+btoa("smik"+ ':' +"asdf")},
fields: {withCredentials: "true"},
data: JSON.stringify(getCurrentDocument()),
success: function(){alert("saved");},
error: function(xhr) { alert("error while saving");}
});
};
// load
loadXHR = function(address) {
alert('loadXHR');
$.ajax({
url: address,
type: "GET",
......@@ -79,13 +57,12 @@ loadXHR = function(address) {
/* username: "smik",
password: "asdf",*/
success: function(data){
alert(data);
var cDoc = getCurrentDocument();
cDoc.load(JSON.parse(data));
cDoc.setAsCurrentDocument();
}
});
}
};
/*
* wait an event before execute an action
......
......@@ -31,10 +31,9 @@
<script type="text/javascript">
// initialize
var addressOfTestDocument = "http://sidunhosted.com/ungdav/test.json";
var initPage = function() {
var pageIWantToTest = "editor";
addressOfTestDocument = "http://sidunhosted.com/webdav/emacs";
setCurrentPage(pageIWantToTest);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment