First of all , I have no idea of javascript, I got this code from a tutorial. I am developing a website in ruby , and to do that I need to make a form of payment. I'm currently using the API Mango. I have the following code:
<form id="form" action="/pay" method="POST">
  <fieldset>
    <div>
      <label for="ccv">Código de seguridad</label>
      <input type="text" id="ccv" required>
    </div>
  </fieldset>
  <input type="submit" value="Pagar ahora!">
</form>
<div id="errores">
</div>
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://js.getmango.com/v1/mango.js"></script>
<script>
  var PUBLIC_API_KEY = 'public_test_u3wbj4jctik1k2u8qtnajhvn82h590ue';
  Mango.setPublicKey(PUBLIC_API_KEY);
  var submission = false;
  var $form = $('#form');
  $form.on('submit', function(event) {
    if (submission) {
      return false;
    }
    submission = true;
    var cardInfo = {
      'ccv': $('#ccv').val()
    };
    Mango.token.create(cardInfo, handleResponse);
    return false;
  });
  function handleResponse(err, data) {
    submission = false;
    //Here I put an error message that's displayed in html
    if (err) {
      ...  
    }
    var token = data.uid;
    var $hidden = $('<input type="hidden" name="token">');
    $hidden.val(token);
    $form.append($hidden);
    $form[0].submit();
  }
</script>
How I can capture that error and show it in html ?
 
     
    