Mailchimp订阅使用jQuery AJAX? [英] Mailchimp subscribe using jQuery AJAX?

查看:148
本文介绍了Mailchimp订阅使用jQuery AJAX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是完整的jQuery解决方案,以订阅用途上Mailchimp列表?

What is a complete jQuery solution to subscribing uses to a list on Mailchimp?

现在的问题是,大多数的解决方案既可以使用图书馆或需要服务器端code。我想快速优雅的解决方案,这给了我完全控制用户界面,形式,因此UX和它的功能。

The problem is that most solutions either use a library or require server side code. I want a quick elegant solution, which gives me complete control over the UI, hence UX of the form and it's functionality.

推荐答案

@纳格拉的解决方案是好的,但如果从客户端的浏览器执行它会抛出一个错误,由于在相同来源安全策略的影响。从本质上说,这些安全措施都没有为 prevent跨站点请求发生时,发件人和发件人都在不同的领域。

@Nagra's solution is good but it will throw an error when executed from the client's browser due to the Same-Origin Security Policies in effect. In essence, these security measures are there to prevent cross site requests that occur when the originator and the sender are on different domains.

如果你看到在JavaScript控制台类似下面的错误,这是一个明确的指示。

If you see errors like the below in the javascript console it is a clear indication.

XMLHtt prequest无法加载的http://你的-MAILCHIMP-网址。没有访问控制 - 允许 - 原产地标头的请求的资源present。产地的http://浏览器的位置,因此不允许访问

XMLHttpRequest cannot load http://YOUR-MAILCHIMP-URL. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin http://BROWSER-LOCATION is therefore not allowed access.

要克服这个问题,脚本需要重写利用CORS或JSONP。由于MailChimp API不支持CORS唯一的选择就是无证JSONP接口。

To overcome this problem the script needs to be rewritten to utilize CORS or JSONP. As the MailChimp API does not support CORS the only option is the undocumented JSONP interface.

更改为利用/订阅/后JSON的网址的版本,也添加和C = 以结束了吗?。一旦URL更新你还需要修改的dataType 在JSON哈希是 JSONP

Change the URL to utilize the /subscribe/post-json? version and also append &c=? to the end. Once the URL is updated you will also need to modify the dataType in the JSON hash to be jsonp

功能的更新前几行应该类似于下面的。

The updated first few lines of the function should resemble the below.

$.ajax({
    url: '//YOUR URL&id=YOUR LIST ID&c=?',
    type: 'POST',
    data: $('#YOUR FORM').serialize(),
    dataType: 'jsonp',

这篇关于Mailchimp订阅使用jQuery AJAX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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