JSFiddle - React, Tailwind, and code Playground
JavaScript
function jsonResponse(json, status, trigger, callback){
this.allgood = function(){$('p').html('all good baby!');};
this.retry = function(response, request){
request.data = {json: '{"response": null, "responseType": "allgood"}'};
delete request.jsonp;
delete request.jsonpCallback;
request.dataType = 'json';
//resend request with confirmation
$.ajax(request);
};
//constructor:
if(typeof this[json.responseType] === 'function'){
this[json.responseType](json.response, trigger, callback, status);
}else{
throw(json);
}
}
$.ajax({
url: '/echo/json/',
data: {json: '{"response": null, "responseType": "retry"}'},
dataType: 'json',
cache: false,
type: 'POST',
success: function(data, status){
jsonResponse(data, status, this);
}
});