This is a continuation of 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) {
}) .fail(function(data){
    // Need to get error messages from Stripe/Charge?
  • Have you got the form working correctly without AJAX, as per the instructions on this page? – Stephen Lewis Jun 11 '17 at 23:04
  • @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. – Jacob Carpenter Jun 13 '17 at 18:29
  • 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. – Stephen Lewis Jun 14 '17 at 1:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.