Last active
April 19, 2017 09:50
-
-
Save Gori4ka/002ed2fadcdaac2fb5a60256f41b8082 to your computer and use it in GitHub Desktop.
WordPress call ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (1) { | |
$('.main').on('submit', 'selector', function (e) { | |
var $form = $(this); | |
e.preventDefault(); | |
wp.ajax.send('action_name', { | |
success: function (response) { | |
$('.alert', $form).addClass('succes').text(response.message); | |
$($form)[0].reset(); | |
setTimeout(function () { | |
$('.alert', $form).removeClass('succes'); | |
}, 5000) | |
}, | |
error: function (response) { | |
$('.alert', $form).addClass('error').text(response.message); | |
}, | |
data: $($form).serializeArray().postArrayToObject(), | |
}); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (1) { | |
$('selector').saiForm({ | |
callbackSubmit: function (thisForm) { | |
wp.ajax.send('action_name', { | |
success: function (response) { | |
$('.alert', thisForm).addClass('succes').text(response.message); | |
$(thisForm)[0].reset(); | |
setTimeout(function () { | |
$('.alert', thisForm).removeClass('succes'); | |
}, 5000) | |
}, | |
error: function (response) { | |
$('.alert', thisForm).addClass('error').text(response.message); | |
}, | |
data: $(thisForm).serializeArray().postArrayToObject(), | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment