0

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"})
Lewis
  • 1,945
  • 5
  • 26
  • 52
  • 1
    Have you tired to load the URL in your browser (or through something like postman) to make sure that your AJAX code isn't the one with the problem? – JM-AGMS May 20 '20 at 20:28
  • The url does seem to trigger a normal response from mailchimp when loaded directly, however, when user data is passed through the form it fails. More specifically it's triggering `error: function(err) {alert("error message");}`. – Lewis May 21 '20 at 09:04
  • I would research what the error returned means. It could be an issue with your form HTML. Other debugging things you can do is output the value of `$form.serialize()` to your browser console to see what data your code is sending. – JM-AGMS May 21 '20 at 12:24

0 Answers0