I seem to be only receiving 403 Forbidden responses from Mail Chimp while using GET
requests. Interestingly enough, POST
requests work fine.
Specifically, my goal is to use JSON to bypass the Mail Chimp redirect as outlined by another Stack user here. I've read through the linked thread a few times and tried a few of the answers with no joy.
I'm suspecting the url is the problem but I'm not sure. The reason I'm suspecting the url is due to the age of the linked answer. Has anyone encountered the same issue or similar. I don't think it's my call, but if anyone can spot anything out of sorts with it I'd appreciate the tip.
https://xxxxx.us16.list-manage.com/subscribe/post-json?u=xxxxx&id=xxxxxx&c=?
Updated url to:
https://xxxxx.us16.list-manage.com/subscribe/post-json?u=xxxxx&id=xxxxxx&c=?
Here's what I have for my ajax call based upon the previously linked question with a few minor tweaks;
$(document).ready(function() {
var $form = $('form');
if ($form.length > 0) {
$('.preference-submit').click(function(e) {
e.preventDefault();
register($form);
});
}
});
function register($form) {
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize(),
cache: false,
dataType: 'json',
contentType: "application/json; charset=utf-8",
error: function(err) { // This is firing when the user submits form...
alert("Could not connect to the registration server. Please try again later.");
},
success: function(data) {
if (data.result != "success") {
alert(data.msg);
} else {
$('.success-alert').show();
}
}
});
}
To answer @JM-AGMS's question, running the url within the browser does return a empty json response such as;
{"result":"error","msg":"1 - Please enter a value"}
Updated url response:
?({"result":"error","msg":"1 - Please enter a value"})