Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Trying to use as much of the original code as possible; here is a solution:</p> <p><em>Post form with post back</em> <a href="http://jsfiddle.net/tpm7v/4/" rel="nofollow">http://jsfiddle.net/tpm7v/4/</a></p> <p><em>Post form via Ajax</em> <a href="http://jsfiddle.net/tpm7v/5/" rel="nofollow">http://jsfiddle.net/tpm7v/5/</a></p> <pre><code> var retries = 0, token = "toki wartooth is not a bumblebee", sendRequest, handelResponse, postFormToServer, $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 }); }; postFormToServer = function() { $.ajax({ type: "POST", cache: "false", url: "/remoteCallToTakFormData", dataType: "json", data: $form.serialize(), success: function() { alert('success!'); } }); }; handelResponse = function(data, code, jqXHR) { switch (data.status) { case "SUCCESS": postFormToServer(); break; case "PENDING": if (retries &lt; 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(); } ​ ​ </code></pre> <p>Keep in mind I am going off the code your provided. You should be able to port this to work with your actual implementation. You may also want to try something like <a href="https://github.com/webadvanced/takeCommand" rel="nofollow">https://github.com/webadvanced/takeCommand</a> to help clean up all the Ajax calls.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload