Skip to content

Instantly share code, notes, and snippets.

@henriqueutsch
Last active February 10, 2018 13:05
Show Gist options
  • Save henriqueutsch/e3f2161974c0ba241a7d218c0cbc2bbb to your computer and use it in GitHub Desktop.
Save henriqueutsch/e3f2161974c0ba241a7d218c0cbc2bbb to your computer and use it in GitHub Desktop.
Mautic Ajax
Failed to load https://domain.mautic.net/form/submit?formId=1: Redirect from 'https://domain.mautic.net/form/submit?formId=1' to 'https://domain.mautic.net/form/message' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4567' is therefore not allowed access.
form#newsletterform method="post" action="https://mydomain.mautic.net/form/submit?formId=1"
div.mauticform-error
div.mauticform-message
div.control.has-icons-left.has-icons-right
input.input name="mauticform[nome]" type="text" placeholder="Insira seu nome completo" required="required"
span.icon.is-small.is-left
i.fas.fa-user
br
div.control.has-icons-left.has-icons-right
input.input name="mauticform[email]" type="email" placeholder="Insira seu melhor email" required="required"
span.icon.is-small.is-left
i.fas.fa-envelope
br
input type="hidden" name="mauticform[formId]" value="1"
input type="hidden" name="mauticform[return]" value=""
inpu type="hidden" name="mauticform[formName]" value="newletter"
div.control
button.button.is-primary name="mauticform[inscrever]" Inscrever
$("#newsletterform").submit(function(e) {
// alert("Formulario");
url = $(this).attr('action');
data = $(this).serialize();
// alert(url);
alert(data);
e.preventDefault();
$.ajax({
url: $(this).attr('action'),
type: 'post',
data: $(this).serialize(),
xhrFields: { withCredentials: true},
// dataType: 'json',
headers: {
'Access-Control-Allow-Origin': 'http://localhost:4567',
'Access-Control-Allow-Credentials':'true',
// 'Access-Control-Request-Headers': 'x-requested-with'
// 'Accept': 'application/json',
// 'Content-Type': 'application/x-www-form-urlencoded'
},
success: function(data)
{
alert("successful");
// console.log('Submission was successful.');
alert(data); // show response from the php script.
},
error: function (data) {
alert("fail");
// console.log('An error occurred.');
alert(data);
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment