marcorivm
10/29/2013 - 4:12 PM

Quick form send using ajax.

Quick form send using ajax.

    <script>
      $('#ajax_form').on('submit','form', function(event) {
        $.post(this.action, $(this).serialize(), function(data) {
          data = JSON.parse(data);
          if(typeof data.success !== "undefined") {
            alert(data.success);
          } else {
            var errors = ['Error!'];
            for(key  in data ) {
              if(data.hasOwnProperty(key)) {
                errors.push(data[key]);
              }
            }
            alert(errors.join('\n'));
          }
        });
        event.preventDefault();
        return false;
      });
    </script>