I have a plugin that has an onBeforeSaveUser event. This fires the mailchimpsubscribe plugin to subscribe users to selected newsletters.
Everything works correctly the user is subscribed and then the saveUser function saves the users newsletter preferences to the database.
I am now trying to get it to work with an ajax call, which again works correctly and subscribes the user to mailchimp. However after sending the json response it does not appear that the saveUser function is being fired as nothing is updated in the database for the selections made.
Could the ajax be stopping the saveUser from being fired?
Ajax:
// Get the post data
var data = $(this).serialize();
// Send it to the server
$.post('/', data, function (response) {
if (response.success) {
$form.parents('.question-box').fadeOut(function () {
$(this).remove();
$('.question-box').first().fadeIn();
});
} else {
var message = response.message;
alert('Unfortunately, we were unable to save your data at this point. Please try again later.'+message);
}
});
Mailchimp Plugin:
if ($api->errorCode) { // an api error occured
// Respond appropriately to Ajax Requests.....
} else { // list subscribe was successful
// Respond appropriately to Ajax Requests
if (craft()->request->isAjaxRequest())
{
return $this->returnJson(array(
'success' => true,
'errorCode' => 1,
'values' => array(
'email' => $email,
'vars' => $vars
)
));
}
//.....
}
Cheers