codestar-framework
codestar-framework copied to clipboard
AJAX errors are improperly handled
Codestar version: v2.2.5 Though I've provide a certain version, this problem is existed for a long time, including the newest one (v2.2.6).
What's happening
While encounter Server Error or Network Issue admin-ajax.php, an alert() will appear with a content like this:
function(){return u(n),r.apply(this,arguments)}
In pratice, an alert like this can be very confusing since it doesn't provide any useful information. User can only find out what's happening by checking DevTools, which is certainly not friendly to a random end user.
What's expected
A short text about the underlying network error can be shown. It will be better if this text can be customized.
Possible reason
I've found in CodeStar,jquery is used to handle AJAX request. In main.min.js, a error handler of AJAX request is like this:
_.wp.ajax.post("csf_" + r.data("unique") + "_ajax_save", {
data: I("#csf-form").serializeJSONCSF()
})
.fail(function(e) {
alert(e.error)
}))
However, the first argument of jqXHR.fail() is a jqXHR object, and its error field is a function according to the document. Thus, ajax error won't print out correctly and instead, the source code of fail() will be printed.