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();} ...@@ -37,41 +37,19 @@ currentTime = function() {return (new Date()).toUTCString();}
// save // save
saveXHR = function(address) { saveXHR = function(address) {
//create request alert("Saving"+address);
var xhr=null; $.ajax({
try url: address,
{ type: "PUT",
xhr = new XMLHttpRequest(); headers: {Authorization: "Basic "+btoa("smik"+ ':' +"asdf")},
} catch(e) fields: {withCredentials: "true"},
{ data: JSON.stringify(getCurrentDocument()),
try {xhr = new ActiveXObject("Msxml2.XMLHTTP");} success: function(){alert("saved");},
catch (e2) error: function(xhr) { alert("error while saving");}
{ });
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()));
}
// load // load
loadXHR = function(address) { loadXHR = function(address) {
alert('loadXHR');
$.ajax({ $.ajax({
url: address, url: address,
type: "GET", type: "GET",
...@@ -79,13 +57,12 @@ loadXHR = function(address) { ...@@ -79,13 +57,12 @@ loadXHR = function(address) {
/* username: "smik", /* username: "smik",
password: "asdf",*/ password: "asdf",*/
success: function(data){ success: function(data){
alert(data);
var cDoc = getCurrentDocument(); var cDoc = getCurrentDocument();
cDoc.load(JSON.parse(data)); cDoc.load(JSON.parse(data));
cDoc.setAsCurrentDocument(); cDoc.setAsCurrentDocument();
} }
}); });
} };
/* /*
* wait an event before execute an action * wait an event before execute an action
......
...@@ -31,10 +31,9 @@ ...@@ -31,10 +31,9 @@
<script type="text/javascript"> <script type="text/javascript">
// initialize // initialize
var addressOfTestDocument = "http://sidunhosted.com/ungdav/test.json";
var initPage = function() { var initPage = function() {
var pageIWantToTest = "editor"; var pageIWantToTest = "editor";
addressOfTestDocument = "http://sidunhosted.com/webdav/emacs";
setCurrentPage(pageIWantToTest); 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