I want to send an automatic back office email when user click on a button (to request support) on frontend. Then I just display a confirmation message (we ll get back to you shortly).
So I made a plugin controller sending email.
And my idea was to attach an ajax call with a jquery on click
stuff to that button.
So I did this.
// SUPPORT ADHERENT button click
$(".call-support a").on("click", function(e, visible) {
e.preventDefault();
var data = {
// ...
};
$.ajax({
method: 'POST',
url: '/actions/unep/toolBox/requestBrandingHelp',
data: data,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function(data) {
console.log('success', data);
})
.error(function(data) {
console.log('error', data);
});
});
My controller is called and send an email but I got a 404 error from the ajax call in console:
I checked that ajax call with Craft.postActionRequest
here below but it is for back-end scope only.
http://buildwithcraft.com/docs/plugins/controllers#posting-to-controller-actions-with-javaScript
How reference "Craft" js object in jquery scope
I am a bit lost how to do that correctly...