I am creating a poll that website visitors can then vote. I use a hosted CMS (Business Catalyst) so I have to do a lot of this with javascript.I have the poll working but when I click submit it is taking around 15 to 20 seconds for the poll to submit. I really need to improve this performance but unsure how to do so. Below is the script I am using. I did not write this but followed some examples for getting it to work. I am using Business Catalyst's Web Apps to create the poll.Here is how it works. There is a form on a page that looks like this:<form id=pollAnswers12003343>    <div class=answers>            <input id=a1 type=radio name=radioChoice value=CAT_Custom_2> Answer 1<br>            <input id=a2 type=radio name=radioChoice value=CAT_Custom_4> Answer 2<br>            <input id=a3 type=radio name=radioChoice value=CAT_Custom_6> Answer 3<br>    </div><button class=button brand vote-btn12003343 type=submit disabled>Vote</button><div class=hide vote-loader12003343>Your vote is submitting, please wait while we tally the votes. <i class=ub ub-refresh ub-spin></i></div></form>The script sees which option the user sees and adds a 1 to the total votes. We then take the information and submit it to the system.Because we are using web apps, BC required the user to be logged in. Since we do not want to require a user to be logged in to vote, we log in an anonymous user, unless they are already logged in. Take the data, submit the data, logout the anonymous user (we do not log out a logged in user) and reload the page.Any code in {{ }} is rendered on the server. For example {{itemid}} would render 123456, the ID of that web app item.Here is the code being used.var Engine = {ui : {pollSubmit : function(){if($(#pollAnswers{{itemid}}).size() === 0){return;}var $form = $(#pollAnswers{{itemid}}), // ID of Poll    $radioOptions = $form.find(input[type='radio']),    $webAppItemName = {{name}}, //{{name}} is a system tag that will render the name of the poll    $formButton = $form.find(button),    bcField_1 = CAT_Custom_2,    answer_1 = parseInt({{this.['Answer 1 Votes']}}),    bcField_2 = CAT_Custom_4,    answer_2 = parseInt({{this.['Answer 2 Votes']}}),       bcField_3 = CAT_Custom_6,    answer_3 = parseInt({{this.['Answer 3 Votes']}}),    $formSubmitData = ,    preElem;    $radioOptions.on( change, function() {        $formButton.removeAttr(disabled);     });    $formButton.on( click, function(e){      e.preventDefault();      var chosenField = $radioOptions.filter(':checked').val();          if(chosenField == bcField_1){              answer_1 = answer_1 + 1;              $formSubmitData = {                ItemName: $webAppItemName,                CAT_Custom_1: {{this.['Answer 1']}},                CAT_Custom_2: answer_1,                CAT_Custom_3: {{this.['Answer 2']}},                CAT_Custom_4: answer_2,                CAT_Custom_5: {{this.['Answer 3']}},                CAT_Custom_6: answer_3,                CAT_Custom_21: {{this.['Suggested by']}}              };          }          if(chosenField == bcField_2){              answer_2 = answer_2 + 1;              $formSubmitData = {                ItemName: $webAppItemName,                CAT_Custom_1: {{this.['Answer 1']}},                CAT_Custom_2: answer_1,                CAT_Custom_3: {{this.['Answer 2']}},                CAT_Custom_4: answer_2,                CAT_Custom_5: {{this.['Answer 3']}},                CAT_Custom_6: answer_3,                CAT_Custom_21: {{this.['Suggested by']}}              };          }          if(chosenField == bcField_3){              answer_3 = answer_3 + 1;              $formSubmitData = {                ItemName: $webAppItemName,                CAT_Custom_1: {{this.['Answer 1']}},                CAT_Custom_2: answer_1,                CAT_Custom_3: {{this.['Answer 2']}},                CAT_Custom_4: answer_2,                CAT_Custom_5: {{this.['Answer 3']}},                CAT_Custom_6: answer_3,                CAT_Custom_21: {{this.['Suggested by']}}              };          }          prepForm($formSubmitData);    });    function prepForm(formSubmitData){            //Slides up the vote button and slides down a spinner.            $( .vote-btn{{itemid}} ).slideUp();            $( .vote-loader{{itemid}} ).slideDown();            //Sets a cookie to let us know they have voted.            Cookies.set('vote{{itemid}}', '1');            //Log user in (if already logged in then we run fireForm(formSubmitData); instead)            logAnonUserIn(formSubmitData);     }     //User must be logged in to submit a web app. To bypass this, we login an anonymous  user.    //If user is logged in to the site, this function is not loaded by the system and the next function is ran.    function logAnonUserIn(formSubmitData){      $.ajax({        type: 'POST',        url: '/ZoneProcess.aspx?ZoneID=-1&Username=anon&Password=anon',        async: true,        beforeSend: function(){},        success: function(){},        complete: function(){         fireForm(formSubmitData);        }      });    }    //This is the function that takes the above data and submits it to the CMS.    function fireForm(formSubmitData){      var url = /CustomContentProcess.aspx?A=EditSave&CCID=30980&OID={{itemid}}&OTYPE=35;        $.ajax({            type: 'POST',            url: url,            data: formSubmitData,            async: true,            success: function() {},            error: function() {},            complete: function(){                logOutUser();             }        });    }    //Once the form is submitted, we want to logout the user if they are logged in anonymously.    //If user is logged in with their account, then we reload the page and do not log them out.    function logOutUser(){      $.ajax({        type: 'GET',        url: '/LogOutProcess.aspx',        complete: function(){          location.reload();         }      });    }}// pollSubmit}// end ui};Engine.ui.pollSubmit();Any thoughts on how to improve the performance of this script?UpdateI added console.log to each complete: function(){} to follow the status of the submissions. It appears the longest portion is logging in the anonymous user. After that, it appears to move quickly, at least quick enough. 
Slow Performance of AJAX Submitted Webform
javascript;performance;jquery