jquery ajax文档,插件 jQuery.ajaxchimp 中文API文档

ajaxChimp

AjaxChimp is a jQuery plugin that lets you ajaxify your mailchimp form.

Use this if you hate the jarring transition to the mailchimp website upon submitting an email address to mailchimp.

Note: This relies on an undocumented feature at mailchimp that uses JSONP to allow cross-domain ajax to work. You have been warned. (It has however, been around for at least 3 years that I know of, and probably more.)

Install

Just add the script to your webpage (along with jQuery ofcourse). Get it here:

curl -O https://raw.githubusercontent.com/scdoshi/jquery-ajaxchimp/master/jquery.ajaxchimp.js

bower

bower install ajaxchimp

Requirements

jQuery

Note: Developed with 1.9.1, but it should work with earlier versions. If it does or does not work with a particular version, please open an issue on github.

Use

On the mailchimp form element

$('form-selector').ajaxChimp();

Label

If a label element is included in the form for the email input, then the success or error message will be displayed in it. A valid or error class will also be added accordingly.

Example Form

Submit

$('#mc-form').ajaxChimp({

url: 'http://blahblah.us1.list-manage.com/subscribe/post?u=5afsdhfuhdsiufdba6f8802&id=4djhfdsh9'

});

Options

Callback

Optionally, you can specify a callback with either method to run after the

ajax query to mailchimp succeeds or fails.

$('form-selector').ajaxChimp({

callback: callbackFunction

});

The JSONP response from mailchimp will be passed to the callback function

function callbackFunction (resp) {

if (resp.result === 'success') {

// Do stuff }

}

URL

You can specify the mailchimp URL to post to (or override the url provided on the form element)

$('form-selector').ajaxChimp({

url: 'mailchimp-post-url'

});

The mailchimp post url will look like this:

http://blahblah.us1.list-manage.com/subscribe/post?u=5afsdhfuhdsiufdba6f8802&id=4djhfdsh99f

Language Support

For success and error messages in different languages:

Specify the language as an option.

Include jquery.ajaxchimp.langs.js in the html file

$('form-selector').ajaxChimp({

language: 'es'

});

Note: If the language you want is not supported out of the box, or the translations are wrong, open a pull request with the required language and I will add it in.

You can also add custom translations just for your website:

$.ajaxChimp.translations.es = {

'submit': 'Grabación en curso...',

0: 'Te hemos enviado un email de confirmación',

1: 'Por favor, introduzca un valor',

2: 'Una dirección de correo electrónico debe contener una sola @',

3: 'La parte de dominio de la dirección de correo electrónico no es válida (la parte después de la @:)',

4: 'La parte de usuario de la dirección de correo electrónico no es válida (la parte antes de la @:)',

5: 'Esta dirección de correo electrónico se ve falso o no válido. Por favor, introduce una dirección de correo electrónico real'

}

The mapping to english for mailchimp responses and the submit message are as follows:

// Submit Message // 'submit': 'Submitting...'

// Mailchimp Responses // 0: 'We have sent you a confirmation email' // 1: 'Please enter a value' // 2: 'An email address must contain a single @' // 3: 'The domain portion of the email address is invalid (the portion after the @: )' // 4: 'The username portion of the email address is invalid (the portion before the @: )' // 5: 'This email address looks fake or invalid. Please enter a real email address'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1、一个众所周知的问题,Ajax直接请求普通文件存在跨域无权限访问的问题,甭管你是静态页面、动态网页、web服务、WCF,只要是跨域请求,一律不准;   2、不过我们又发现,Web页面上调用js文件时则不受是否跨域的影响(不仅如此,我们还发现凡是拥有”src”这个属性的标签都拥有跨域的能力,比如[removed]、、<iframe>);   3、于是可以判断,当前阶段如果想通过纯web端(ActiveX控件、服务端代理、属于未来的HTML5之Websocket等方式不算)跨域访问数据就只有一种可能,那就是在远程服务器上设法把数据装进js格式的文件里,供客户端调用和进一步处理;   4、恰巧我们已经知道有一种叫做JSON的纯字符数据格式可以简洁的描述复杂数据,更妙的是JSON还被js原生支持,所以在客户端几乎可以随心所欲的处理这种格式的数据;   5、这样子解决方案就呼之欲出了,web客户端通过与调用脚本一模一样的方式,来调用跨域服务器上动态生成的js格式文件(一般以JSON为后缀),显而易见,服务器之所以要动态生成JSON文件,目的就在于把客户端需要的数据装入进去。   6、客户端在对JSON文件调用成功之后,也就获得了自己所需的数据,剩下的就是按照自己需求进行处理和展现了,这种获取远程数据的方式看起来非常像AJAX,但其实并不一样。   7、为了便于客户端使用数据,逐渐形成了一种非正式传输协议,人们把它称作JSONP,该协议的一个要点就是允许用户传递一个callback参数给服务端,然后服务端返回数据时会将这个callback参数作为函数名来包裹住JSON数据,这样客户端就可以随意定制自己的函数来自动处理返回数据了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值