amforms icon indicating copy to clipboard operation
amforms copied to clipboard

Ajax Sending

Open waswebb opened this issue 7 years ago • 7 comments

Hi

First i want to say that this plugin is a very cool one. I like your work, thx.

But it would be nice to have the option to send the form over Ajax. Do you plan to add this option?

waswebb avatar Apr 25 '17 09:04 waswebb

We are planning to add this option in time.

hubertprein avatar Jun 12 '17 12:06 hubertprein

+1 would love to see this added.

CreateSean avatar Sep 11 '17 14:09 CreateSean

It seems to handle ajax submissions just fine for me? Am I missing something here?

thisisjamessmith avatar Oct 27 '17 16:10 thisisjamessmith

@thisisjamessmith are you just submitting to 'amForms/submissions/saveSubmission' via ajax?

The following doesn't work for me, getting 404;

var xhr = new XMLHttpRequest();
xhr.open('POST', 'amForms/submissions/saveSubmission', true);
xhr.setRequestHeader('Accept', 'application/json; charset=utf-8');
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');

// Send the collected data as JSON
xhr.send(JSON.stringify(formData));

Moorst avatar Jan 04 '18 10:01 Moorst

No, I'm submitting to the form's action attribute (which is actually empty, so defaults to posting to the current page).

I'm using jQuery - something like this:

ajaxSubmit: function($form, $thanks, e){
  e.preventDefault();
  
  $.ajax({
    type:'POST',
    url: $form.attr('action'),
    data: $form.serialize(),
    cache: false
  }).done(function(data){
    //success...
    if (data.success){
      // remove loading and show success message
    }
    // errors...
    else{
      if (data.errors){
        $.each(data.errors, function(field, msgs){
          // show errors by each errored field
        });
      }
    }
  });
},

thisisjamessmith avatar Jan 04 '18 10:01 thisisjamessmith

Ahh ok great, I'll give that a go. Thanks!

Moorst avatar Jan 04 '18 10:01 Moorst

@thisisjamessmith You save my day! Thank you!

ipetrov87 avatar Mar 01 '18 20:03 ipetrov87