0

I'm trying to migrate a feature which was written in jquery to angularjs. So instead of using jquery's ajax method, I am trying to use angularjs' $http method. The code allows a user to sign up for a mailchimp newsletter. Interestingly, when I use the jquery method, there are no issues. However, when I use the angularjs method, I get a 404 error, even though I can see in the network requests that a response from mailchimp is available. What am I doing wrong with angularjs?

I will post the two snippets of code bellow:

AngularJS

 $http({
    method: "JSONP",
    url:
      "https://XXX.us4.list-manage.com/subscribe/post-json? 
       u=XXX&amp&id=XXX&c=?",
    params: { EMAIL: this.text },
  }).then(
    function successCallback(response) {
      console.log("success");
      console.log(response);
    },
    function errorCallback(response) {
      console.log("error");
      console.log(response);
    }
  );

jQuery ajax

  function successCallback(resp) {
    console.log(resp);
  }

  $.ajax({
    url:
      "https://XXX.us4.list-manage.com/subscribe/post-json? 
       u=XXX&amp&id=XXX&c=?",
    data: { EMAIL: this.text },
    success: successCallback,
    dataType: "jsonp",
    error: function(resp, text) {
      console.log("mailchimp ajax submit error: " + text);
    }
  });
};
1
  • I can't help specifically, but to diagnose the issue look at both requests in the network tab of dev tools and look for differences. Commented Jan 16, 2020 at 14:31

1 Answer 1

1

From the Docs:

Note that, since JSONP requests are sensitive because the response is given full access to the browser, the url must be declared, via $sce as a trusted resource URL. You can trust a URL by adding it to the whitelist via $sceDelegateProvider.resourceUrlWhitelist or by explicitly trusting the URL via $sce.trustAsResourceUrl(url).

For more information, see

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.