Description
Hellos~
When using the API Feature and routing through $.fn.api.settings.successTest, the onComplete() & onFailure() json response param does not match the datatype specified (tested for json).
To explain further... when the successTest fails, the onFailure() json response is a textual json string and not in object notation. Also, onComplete() json response is a parent object instead of the expected ajax response object.
Conversely, when successTest succeeds, the onComplete() and onSuccess() json response is in the expected object notation.
Also, this issue required me to use fiddle's /echo/ ajax service, as using SUI's built-in mock feature, gives the correct object notation in all cases. I'm thinking this is an issue in the coding related specifically to the ajax handler. (wild guess ^o^;;).
FYI. Example displays output to console...
Fiddle: http://jsfiddle.net/Airforce111/sv13cujv/
For reference...
<div id="submit_test" class="ui labeled icon primary ok button">
<i class="edit icon"></i> Click Me!
</div>
body {
padding: 1em;
}
$.fn.api.settings.successTest = function(response) {
if (response && response.success) {
return response.success;
}
return false;
};
$.fn.api.settings.api = {
'create general test' : '/echo/json/',
};
$('#submit_test').api({
method: 'POST',
action: 'create general test',
urlData: {},
//data: {},
dataType: 'json',
beforeSend: function(settings) {
// Create POST Data.
settings.data = {
json: JSON.stringify({
success: false, // Change this to true|false
message: 'message',
data: {
errors: ['error_code_1', 'error_code_2']
}
}),
delay: 1
};
return settings;
},
beforeXHR: function(xhrObject) {},
onComplete: function(json, element) {
console.log('onComplete');
console.log(json, 'OK! Is an Object, but watch contents on success/fail.');
console.log(json.data, 'Data Depends on onSuccess/onFailure');
alert('onComplete!');
},
onSuccess: function(json, element) {
console.log('onSuccess');
console.log(json, 'OK! Is an Object.');
console.log(json.data, 'Data Available');
alert('onSuccess!');
},
onFailure: function(json, element) {
console.log('onFailure');
console.log(json, 'Failed! Should be an Object.');
console.log(json.data, 'Data Failed');
alert('onFailure!');
},
onError: function(errorMessage, element) {},
onAbort: function(errorMessage, element) {}
});