JSFiddle - React, Tailwind, and code Playground
JavaScript
var retries = 0,
token = "toki wartooth is not a bumblebee",
sendRequest,
handelResponse,
$theForm = $('#tehForm');
$(document).ready(function() {
// Attach the action to the form
$theForm.bind('submit', onsubmit_action);
});
sendRequest = function() {
$.ajax({
type: "POST",
cache: "false",
url: "/remoteCall",
dataType: "json",
data: {
ref_token: token
},
success: handelResponse
});
};
handelResponse = function(data, code, jqXHR) {
switch (data.status) {
case "SUCCESS":
alert("Success");
$theForm.bind('submit', onsubmit_action);
$theForm.submit();
// --> HERE IS WHERE I WANT THE FORM TO SUBMIT <--
$theForm.submit();
break;
case "PENDING":
if (retries < 9) {
retries += 1;
setTimeout(sendRequest , 1000);
} else {
alert("Failed after 9 tries");
}
break;
case "ERROR":
alert("Error");
break;
default:
alert("Some kind of horrible error occurred");
break;
}
};
function onsubmit_action(evt) {
evt.preventDefault();
sendRequest();
}