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&&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&&id=XXX&c=?",
data: { EMAIL: this.text },
success: successCallback,
dataType: "jsonp",
error: function(resp, text) {
console.log("mailchimp ajax submit error: " + text);
}
});
};