Body: <p>This is a continuation of <a href="https://craftcms.stackexchange.com/questions/20269/how-could-i-submit-the-charge-plugin-using-ajax">How could I submit the Charge plugin using Ajax?</a></p>
  
  <p>I'm using the Charge plugin to handle my Stripe payments. I'm having to use ajax to submit the charge form before submitting a second form that is on the page. The problem is when the ajax call fails, I can't seem to get the error messages that are causing the failed attempt. </p>
  
  <p>I'm pretty sure part of the reason is because I get a 404 every time it fails, because <code>'url: charge/charge'</code> path doesn't actually exist on my server. So, <code>console.log(data)</code> is basically useless to try and find how to access the error(s).</p>
  
  <p>This is the code that I currently have: </p>
  
  <pre><code>this.ajaxReq = $.ajax({
    method: "post",
    url: 'charge/charge',
    data: $('#charge-form').serialize()
  }) .done(function(data) {
      console.log('success');
  }) .fail(function(data){
      console.log('failed');
      // Need to get error messages from Stripe/Charge?
  }); 
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-11T23:04:54.393Z
Comments.Text: Have you got the form working correctly _without_ AJAX, as per the instructions [on this page](https://squarebit.co.uk/software/craft/charge/usage/quickstart/using-stripe-js)?
Comments.UserDisplayName: Stephen Lewis
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-13T18:29:16.487Z
Comments.Text: @StephenLewis Yes, I was able to get it working properly per the documentation. However, I'm needing to submit a freeform form whenever I submit the charge form, thus why I'm submitting via AJAX.
Comments.UserDisplayName: Jacob Carpenter
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-14T01:59:27.090Z
Comments.Text: Well, if it works without AJAX, then the Charge route (`charge/charge`) must be working correctly. The Freeform stuff sounds rather convoluted, but I assume you have your reasons for doing it that way.
Comments.UserDisplayName: Stephen Lewis
Tags: <plugins><error-message><ajax><plugin-charge>
Title: SquareBit Charge Plugin: How to retrieve error messages from failed ajax call?
ThreadText: # SquareBit Charge Plugin: How to retrieve error messages from failed ajax call?
  
  (Asked by: username_0 on 2017-06-08)
  
  This is a continuation of [How could I submit the Charge plugin using Ajax?](https://craftcms.stackexchange.com/questions/20269/how-could-i-submit-the-charge-plugin-using-ajax)
  
  I'm using the Charge plugin to handle my Stripe payments. I'm having to use ajax to submit the charge form before submitting a second form that is on the page. The problem is when the ajax call fails, I can't seem to get the error messages that are causing the failed attempt.
  
  I'm pretty sure part of the reason is because I get a 404 every time it fails, because `'url: charge/charge'` path doesn't actually exist on my server. So, `console.log(data)` is basically useless to try and find how to access the error(s).
  
  This is the code that I currently have:
  
  ```
  this.ajaxReq = $.ajax({
    method: "post",
    url: 'charge/charge',
    data: $('#charge-form').serialize()
  }) .done(function(data) {
      console.log('success');
  }) .fail(function(data){
      console.log('failed');
      // Need to get error messages from Stripe/Charge?
  }); 
  
  ```
  
  **Tags:** plugins, error-message, ajax, plugin-charge
  
  > **Comments:**
  > **username_1**: Have you got the form working correctly _without_ AJAX, as per the instructions [on this page](https://squarebit.co.uk/software/craft/charge/usage/quickstart/using-stripe-js)?  
  > **username_0**: @username_1 Yes, I was able to get it working properly per the documentation. However, I'm needing to submit a freeform form whenever I submit the charge form, thus why I'm submitting via AJAX.  
  > **username_1**: Well, if it works without AJAX, then the Charge route (`charge/charge`) must be working correctly. The Freeform stuff sounds rather convoluted, but I assume you have your reasons for doing it that way.  
  
  ---
  
  ## 0 answers
  
  