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){
console.log($.extend({}, request));
request.data = {json: '{"responseType": "allgood"}'};
delete request.jsonpCallback;
delete request.jsonp;
//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": "are you sure?", "responseType": "retry"}'},
dataType: 'json',
cache: false,
type: 'POST',
success: function(data, status){
jsonResponse(data, status, this);
}
});