0

I am using the Charge plugin to handle my Stripe payments. How could I submit this form via Ajax Post and get the response? I have tried using the following code but it tells me it's a bad request:

this.ajaxReq = $.ajax({
   url: 'charge/charge',
   data: $('#charge-form').serialize()
}) .done(function(data) {
   console.log('success!');
   console.log(data);
}) .fail(function(data){
   console.log(data);
});
  • Are you using the Stripe.js checkout option, as detailed in the Charge documentation? – Stephen Lewis Apr 29 '17 at 18:34
  • Yes, I'm looking to modify the $form.get(0).submit(); that's part of jquery.charge so that this submission is sent via Ajax without a page refresh – user2315552 Apr 29 '17 at 23:27
  • 1
    Have you specified the $.ajax method? It uses GET by default, but you need to submit the form using POST. – Stephen Lewis Apr 30 '17 at 4:11
  • You're welcome. I added my comment as an answer. If you can accept it, then we can close this one out. – Stephen Lewis Apr 30 '17 at 23:15
1

You need to specify the HTTP method used by the $.ajax method.

By default, it uses GET, but you need to submit the form using POST.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.