switching to full JSON API without POST array use, ensure all JSON operations are done with error detection

This commit is contained in:
El RIDO 2019-05-13 22:31:52 +02:00
parent be1e7babc0
commit cc1c55129f
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92
14 changed files with 187 additions and 103 deletions

View file

@ -3712,27 +3712,22 @@ jQuery.PrivateBin = (function($, RawDeflate) {
{
let isPost = Object.keys(data).length > 0,
ajaxParams = {
type: isPost ? 'POST' : 'GET',
url: url,
headers: ajaxHeaders,
success: function(result) {
if (result.status === 0) {
success(0, result);
} else if (result.status === 1) {
fail(1, result);
} else {
fail(2, result);
type: isPost ? 'POST' : 'GET',
url: url,
headers: ajaxHeaders,
dataType: 'json',
success: function(result) {
if (result.status === 0) {
success(0, result);
} else if (result.status === 1) {
fail(1, result);
} else {
fail(2, result);
}
}
}
};
};
if (isPost) {
ajaxParams.data = data;
['adata', 'meta'].map(function (key) {
if (data.hasOwnProperty(key)) {
ajaxParams.data[key] = JSON.stringify(data[key]);
}
});
ajaxParams.dataType = 'json';
ajaxParams.data = JSON.stringify(data);
}
$.ajax(ajaxParams).fail(function(jqXHR, textStatus, errorThrown) {
console.error(textStatus, errorThrown);