$(document).ready(function () {

$("#pan_application").submit(function(e){
  e.preventDefault();
  if(confirm("Are you sure to proceed this?")){

    $.ajax({
      type: 'POST',
      url: $('#pan_application').attr('action'),
      data: new FormData(this),
      dataType: 'json',
      contentType: false,
      cache: false,
      processData: false,
      beforeSend: function() {
        $("#submitbtn").html('Processing......').attr("disabled", true);
      },

      success: function(response){
         //console.log(response);
        if(response.status==true){
        $('#pan_application').trigger("reset");
        $("#submitbtn").html('Redicting to NSDL');
        my_form=document.createElement('form');
        my_form.method='POST';
        my_form.action=response.url
        my_form.target="_blank";
        my_input=document.createElement('input');
        my_input.type='hidden';
        my_input.name='req';
        my_input.value=response.enc_data
        my_form.appendChild(my_input);
        document.body.appendChild(my_form);
        my_form.submit();
        setTimeout( function(){ $("#submitbtn").html('Submit').attr("disabled", false); },5000);
        }else{
        alert(response.message);
        $("#submitbtn").html('Submit').attr("disabled", false);
        }

        
      },

      error: function(xhr) {
        alert("Connection Error");
        $("#submitbtn").html('Submit').attr("disabled", false);
      }

    });

  }

});

});