Mailchimp API 收到错误并且无法使用 ajax 成功 [英] Mailchimp API getting error and can't use ajax success

查看:30
本文介绍了Mailchimp API 收到错误并且无法使用 ajax 成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从 mailchimp API V2.0 获取正确响应时遇到问题.

I have problem with getitng correct response from mailchimp API V2.0.

当我尝试订阅新用户时

var arr = {
           apikey:"xxxx",
           id:"secretListId",
           email:{
                  email:"jd@example.com"
                 },
           double_optin:"false"
          }

function jsonpCallback (){
       alert("jsonpCallback");
    };

$.ajax({
      type: 'GET',
      url: 'https://us6.api.mailchimp.com/2.0/lists/subscribe.json',
      dataType: 'jsonp',
      jsonpCallback: 'jsonpCallback',
      data: arr,
      timeout: 4000,
      cache: false,
      async: false, success: function(data, textStatus, jqXHR) {
        alert('success: '+data);
      },
      error: function(jqXHR, textStatus, errorThrown){
        alert('error: '+JSON.stringify(jqXHR));
      },
      complete: function(jqXHR, textStatus){
        alert('complete: '+JSON.stringify(jqXHR));
      }       
    }).success(function(rsp){
        console.log('success: '+rsp);
    }).fail(function(xhr,error,thrownError){
        console.log('fail  status:[' + xhr.status + ']  error:[' + thrownError + ']');
    }).always(function(){
        console.log('complete');
    });
});

在检查器中,我收到错误 500.

In inspector I'm getting error 500.

并在警报弹出窗口中

And in alert popup

在此弹出窗口中显示另一条消息(错误 500).

In this popup shold be another message (with error 500).

但是当我将此链接传递到浏览器时,我得到:

But when I past this link to browser I get:

{
"status": "error",
"code": 214,
"name": "List_AlreadySubscribed",
"error": "jd@example.com is already subscribed to list mpowroznik.com List. Click here to update your profile."

}

当然,如果我添加新电子邮件,我会收到弹出警报

Of course if I add new e-mail I get popup alert

为什么这是错误,而不是成功?

Why this is ERROR, not success ?

我只使用 jQuery,没有使用 PHP 或其他语言.

I'm using only jQuery without PHP or other language.

函数 jsonpCallback 根本不执行.

Function jsonpCallback isn't execute at all.

我必须做什么才能得到正确的响应消息.

What I must do, to get correct response message.

推荐答案

由于非常具体的原因,此 API 不应由浏览器中的代码使用.

This API is not meant to be used by code in the browser for a very specific reason.

通过在浏览器中发出此请求,任何使用发出此请求的页面的人都可以获取您的 api 密钥并向 api 发出自己的请求,就好像他们是您一样,从而允许任何人窃取所有添加到列表中的电子邮件地址(甚至清空列表.)

By making this request in the browser, anyone who uses the page that makes this request will be able to take your api key and make their own requests to the api as if they were you, thus allowing anyone to steal all of the email addresses that are added to your list (and even empty the list.)

您必须使用服务器端语言(例如 PHP)与此 API 交互.否则会损害用户/客户的安全.

You must interact with this api using a server-side language such as PHP. Doing otherwise is compromising the security of your users/customers.

这篇关于Mailchimp API 收到错误并且无法使用 ajax 成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆