title: changing variable inside sweetalert
body: <p>I want to change a variable depending if the user presses ok or not on a confirm. And then I pass the variable into ajax code. </p>
  
  <p>Basically, it works when I write the ajax 3 times(!) inside the function like above. </p>
  
  <p>I tried making it simple by changing the variable update_plan inside the swal and then running the ajax outside the swal but swal doesn't work like a normal alert in that the code continues running and doesn't stop when the alert pops up - as opposed to regular alerts that halt the running of the code. Is there any way to make this more efficient?</p>
  
  <pre><code>var update_plan = 'no';
  
  if($('#form_updated').val() == 'yes'){      
  
    swal({ 
      title: '',  
      text: "Do you want to save this plan for all future refills?",   
      type: "warning",   
      showCancelButton: true,   
      confirmButtonColor: "#39b54a",   
      confirmButtonText: "Yes, save it!",  
      animation: 'slide-from-bottom ', 
      closeOnConfirm: false
      }, 
      function(isConfirm){
        if(isConfirm){
          swal('Saved!','You have switched plans.', 'success');
          update_plan = 'yes';
  
          $.ajax({
            type: "POST",       
            url: "front_end_functions.php",       
            data: "function=save_client_data&amp;cNumber="+cNumber+"&amp;carrier="+carrier+"&amp;plan="+plan+"&amp;update_plan="+update_plan+"&amp;random_2="+random_2,       
            success: function(msg){  
              if(msg == 'error2'){           
                swal('','We have detected a problem. Please try again later.', 'error');
                return false;        
              }else{                    
                var jsArray = JSON.stringify(msg);           
                $('#orange_bg').toggle('slow');           
                get_blue_div(jsArray);                 
              }        
            }
          });
        }else{
  
          $.ajax({
            type: "POST",       
            url: "front_end_functions.php",       
            data: "function=save_client_data&amp;cNumber="+cNumber+"&amp;carrier="+carrier+"&amp;plan="+plan+"&amp;update_plan="+update_plan+"&amp;random_2="+random_2,       
            success: function(msg){  
              if(msg == 'error2'){           
                swal('','We have detected a problem. Please try again later.','error');
                return false;        
              }else{                    
                var jsArray = JSON.stringify(msg);           
                $('#orange_bg').toggle('slow');           
                get_blue_div(jsArray);                 
              }      
            } 
          });
        }  
    });
  
    }else{
  
      $.ajax({
      type: "POST",       
      url: "front_end_functions.php",       
      data: "function=save_client_data&amp;cNumber="+cNumber+"&amp;carrier="+carrier+"&amp;plan="+plan+"&amp;update_plan="+update_plan+"&amp;random_2="+random_2,       
      success: function(msg){  
        if(msg == 'error2'){           
        swal('','We have detected a problem. Please try again later.','error');
        return false;        
        }else{                    
          var jsArray = JSON.stringify(msg);           
          $('#orange_bg').toggle('slow');           
          get_blue_div(jsArray);                 
        }      
      }
    });
  }
  </code></pre>