craftcms / contact-form

Add a simple contact form to your Craft CMS site.
https://plugins.craftcms.com/contact-form
MIT License
293 stars 93 forks source link

Ajax no longer works on craft3 #128

Closed pixaful closed 6 years ago

pixaful commented 6 years ago

On craft2 site I used the script provided for if else statments

$('#my-form').submit(function(ev) { // Prevent the form from actually submitting ev.preventDefault();

// Send it to the server
$.post({
    url: '/',
    dataType: 'json',
    data: $(this).serialize(),
    success: function(response) {
        if (response.success) {
            $('#thanks').fadeIn();
        } else {
            // response.error will be an object containing any validation errors that occurred, indexed by field name
            // e.g. response.error.fromName => ['From Name is required']
            alert('An error occurred. Please try again.');
        }
    }
});

});

But this does not work in craft 3

The success statement does not work

success: function(response) {}

If you need to see working examples, I have sites in both craft2 and 3 to show the issue, as I am in the middle of a migrate.

pixaful commented 6 years ago

scratch that, its not an ajax issue. I have spend a few nights on this but it turns out to be a clashing script!