move jquery ajax to XMLHttpRequest

pull/68/head
Henrique Dias 2016-03-06 13:01:03 +00:00
parent 8043610590
commit fda5c23ae0
2 changed files with 42 additions and 50 deletions

File diff suppressed because one or more lines are too long

View File

@ -234,15 +234,17 @@ $(document).on('page:browse', function() {
filename = window.location.pathname.replace("/admin/browse/", "") + '/' + filename; filename = window.location.pathname.replace("/admin/browse/", "") + '/' + filename;
} }
var content = '{"filename": "' + filename + '"}'; var content = {
filename: filename
};
$.ajax({ var request = new XMLHttpRequest();
type: 'PUT', request.open("PUT", rename.url);
url: rename.url, request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
data: content, request.send(JSON.stringify(content));
dataType: 'json', request.onreadystatechange = function() {
encode: true if (request.readyState == 4) {
}).done(function(data) { if (request.status == 200) {
$.pjax({ $.pjax({
url: window.location.pathname, url: window.location.pathname,
container: '#content' container: '#content'
@ -252,13 +254,15 @@ $(document).on('page:browse', function() {
type: 'success', type: 'success',
timeout: 5000 timeout: 5000
}); });
}).fail(function(data) { } else {
notification({ notification({
text: 'Something went wrong.', text: 'Something went wrong.',
type: 'error' type: 'error'
}); });
console.log(data); console.log(request.responseText);
}); }
}
}
return false; return false;
}); });
@ -306,31 +310,19 @@ $(document).on('page:browse', function() {
request.send(JSON.stringify({ request.send(JSON.stringify({
command: value command: value
})); }));
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200) {
/*$.ajax({ } else {
type: 'POST',
url: window.location.pathname,
data: content,
dataType: 'json',
encode: true,
}).done(function(data) {
notification({
text: "File created successfully.",
type: 'success',
timeout: 5000
});
$.pjax({
url: data.Location,
container: '#content'
})
}).fail(function(data) {
notification({ notification({
text: 'Something went wrong.', text: 'Something went wrong.',
type: 'error' type: 'error'
}); });
console.log(data); console.log(request.responseText);
}); */ }
}
}
return false; return false;
}); });