move editor ajax function to native

This commit is contained in:
Henrique Dias 2016-03-06 13:06:30 +00:00
parent fda5c23ae0
commit 7e27c40841
2 changed files with 25 additions and 26 deletions

File diff suppressed because one or more lines are too long

View File

@ -92,31 +92,30 @@ $(document).on('page:editor', function() {
var data = JSON.stringify($(this).serializeJSON()),
button = $(this).find("input[type=submit]:focus");
$.ajax({
type: 'POST',
url: window.location,
data: data,
headers: {
'X-Regenerate': button.data("regenerate"),
'X-Schedule': button.data("schedule"),
'X-Content-Type': button.data("type")
},
dataType: 'json',
encode: true,
contentType: "application/json; charset=utf-8",
}).done(function(data) {
notification({
text: button.data("message"),
type: 'success',
timeout: 5000
});
}).fail(function(data) {
notification({
text: 'Something went wrong.',
type: 'error'
});
console.log(data);
});
var request = new XMLHttpRequest();
request.open("POST", window.location);
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
request.setRequestHeader("X-Regenerate", button.data("regenerate"));
request.setRequestHeader("X-Schedule", button.data("schedule"));
request.setRequestHeader("X-Content-Type", button.data("type"));
request.send(data);
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200) {
notification({
text: button.data("message"),
type: 'success',
timeout: 5000
});
} else {
notification({
text: 'Something went wrong.',
type: 'error'
});
console.log(request.responseText);
}
}
}
return false;
});