Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajax Sending #144

Open
waswebb opened this issue Apr 25, 2017 · 7 comments
Open

Ajax Sending #144

waswebb opened this issue Apr 25, 2017 · 7 comments

Comments

@waswebb
Copy link

waswebb commented Apr 25, 2017

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?

@hubertprein
Copy link
Contributor

We are planning to add this option in time.

@CreateSean
Copy link

+1 would love to see this added.

@thisisjamessmith
Copy link

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

@Moorst
Copy link

Moorst commented Jan 4, 2018

@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));

@thisisjamessmith
Copy link

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
        });
      }
    }
  });
},

@Moorst
Copy link

Moorst commented Jan 4, 2018

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

@ipetrov87
Copy link

@thisisjamessmith You save my day! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants