Change from deprecated $.parseJSON to JSON.parse.

The jQuery function `parseJSON` is now deprecated so we should push to
switch to native `JSON.parse` since all browsers support it.
This commit is contained in:
Brock Whittaker
2017-07-27 12:48:27 -07:00
committed by Tim Abbott
parent 10265dbbd9
commit ac4ac63353
4 changed files with 8 additions and 11 deletions

View File

@@ -53,7 +53,7 @@ exports.set_up = function () {
error: function (xhr) { error: function (xhr) {
if (xhr.status.toString().charAt(0) === "4") { if (xhr.status.toString().charAt(0) === "4") {
btn.closest("td").html( btn.closest("td").html(
$("<p>").addClass("text-error").text($.parseJSON(xhr.responseText).msg) $("<p>").addClass("text-error").text(JSON.parse(xhr.responseText).msg)
); );
} else { } else {
btn.text(i18n.t("Failed!")); btn.text(i18n.t("Failed!"));
@@ -88,7 +88,7 @@ exports.set_up = function () {
ui_report.success(i18n.t("Custom filter added!"), filter_status); ui_report.success(i18n.t("Custom filter added!"), filter_status);
}, },
error: function (xhr) { error: function (xhr) {
var errors = $.parseJSON(xhr.responseText).errors; var errors = JSON.parse(xhr.responseText).errors;
if (errors.pattern !== undefined) { if (errors.pattern !== undefined) {
xhr.responseText = JSON.stringify({msg: errors.pattern}); xhr.responseText = JSON.stringify({msg: errors.pattern});
ui_report.error(i18n.t("Failed"), xhr, pattern_status); ui_report.error(i18n.t("Failed"), xhr, pattern_status);

View File

@@ -311,7 +311,7 @@ $.get({
update_last_full_update(data.end_times); update_last_full_update(data.end_times);
}, },
error: function (xhr) { error: function (xhr) {
$('#id_stats_errors').show().text($.parseJSON(xhr.responseText).msg); $('#id_stats_errors').show().text(JSON.parse(xhr.responseText).msg);
}, },
}); });
@@ -533,7 +533,7 @@ $.get({
update_last_full_update(data.end_times); update_last_full_update(data.end_times);
}, },
error: function (xhr) { error: function (xhr) {
$('#id_stats_errors').show().text($.parseJSON(xhr.responseText).msg); $('#id_stats_errors').show().text(JSON.parse(xhr.responseText).msg);
}, },
}); });
@@ -651,7 +651,7 @@ $.get({
update_last_full_update(data.end_times); update_last_full_update(data.end_times);
}, },
error: function (xhr) { error: function (xhr) {
$('#id_stats_errors').show().text($.parseJSON(xhr.responseText).msg); $('#id_stats_errors').show().text(JSON.parse(xhr.responseText).msg);
}, },
}); });
@@ -723,6 +723,6 @@ $.get({
update_last_full_update(data.end_times); update_last_full_update(data.end_times);
}, },
error: function (xhr) { error: function (xhr) {
$('#id_stats_errors').show().text($.parseJSON(xhr.responseText).msg); $('#id_stats_errors').show().text(JSON.parse(xhr.responseText).msg);
}, },
}); });

View File

@@ -341,7 +341,7 @@
if (xhr.responseText) { if (xhr.responseText) {
try { try {
serverResponse = jQuery.parseJSON(xhr.responseText); serverResponse = JSON.parse(xhr.responseText);
} }
catch (e) { catch (e) {
serverResponse = xhr.responseText; serverResponse = xhr.responseText;

View File

@@ -644,10 +644,7 @@ $.fn.ajaxSubmit = function(options) {
} }
return (doc && doc.documentElement && doc.documentElement.nodeName != 'parsererror') ? doc : null; return (doc && doc.documentElement && doc.documentElement.nodeName != 'parsererror') ? doc : null;
}; };
var parseJSON = $.parseJSON || function(s) { var parseJSON = $.parseJSON || JSON.parse;
/*jslint evil:true */
return window['eval']('(' + s + ')');
};
var httpData = function( xhr, type, s ) { // mostly lifted from jq1.4.4 var httpData = function( xhr, type, s ) { // mostly lifted from jq1.4.4