ajax post data数据传值分析
2012-10-24 10:57
211 查看
今天在看opencart的代码的时候,看到一个很奇特的写法:
$.ajax({
url: 'index.php?route=checkout/payment_address/validate',
type: 'post',
data: $('#payment-address input[type=\'text\'], #payment-address input[type=\'password\'], #payment-address input[type=\'checkbox\']:checked, #payment-address
input[type=\'radio\']:checked, #payment-address input[type=\'hidden\'], #payment-address select'),
dataType: 'json',
beforeSend: function() {
$('#button-payment-address').prop('disabled', true);
$('#button-payment-address').after('<span class="wait"> <img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('#button-payment-address').prop('disabled', false);
$('.wait').remove();
},
success: function(json) {
$('.warning, .error').remove();
...此处略去代码 n行
data传递参数,这个包括了所有当前页面input type=text域的值,input type=password域的值 ,input type=checkbox 选中域的值 以及radio,hidden,select域的值都会传递过去,在url 处理页面 'index.php?route=checkout/payment_address/validate' ,可以这样接收 来自html页面ajax传过来的值:
$this->request->post['payment_address'],其中payment_address就是 html页面里面的 <input type="radio" name="payment_address" value="existing" id="payment-address-existing" checked="checked" /> 的。
所以data传参数的形式除了{key:value}的形式,还有这样的一种 强大的数据处理方式。
希望对大家有帮助
$.ajax({
url: 'index.php?route=checkout/payment_address/validate',
type: 'post',
data: $('#payment-address input[type=\'text\'], #payment-address input[type=\'password\'], #payment-address input[type=\'checkbox\']:checked, #payment-address
input[type=\'radio\']:checked, #payment-address input[type=\'hidden\'], #payment-address select'),
dataType: 'json',
beforeSend: function() {
$('#button-payment-address').prop('disabled', true);
$('#button-payment-address').after('<span class="wait"> <img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('#button-payment-address').prop('disabled', false);
$('.wait').remove();
},
success: function(json) {
$('.warning, .error').remove();
...此处略去代码 n行
data传递参数,这个包括了所有当前页面input type=text域的值,input type=password域的值 ,input type=checkbox 选中域的值 以及radio,hidden,select域的值都会传递过去,在url 处理页面 'index.php?route=checkout/payment_address/validate' ,可以这样接收 来自html页面ajax传过来的值:
$this->request->post['payment_address'],其中payment_address就是 html页面里面的 <input type="radio" name="payment_address" value="existing" id="payment-address-existing" checked="checked" /> 的。
所以data传参数的形式除了{key:value}的形式,还有这样的一种 强大的数据处理方式。
希望对大家有帮助
相关文章推荐
- ajax post data数据传值分析
- ajax post data 获取不到数据
- 利用FormData收集表单数据实现ajax传递post数据
- ajax post data 获取不到数据,注意 content-type的设置 、post/get
- ajax post data 获取不到数据,注意content-type的设置post/get
- ajax post data 获取不到数据,注意 content-type的设置 、post/get
- ajax有两种提交数据的方式,分别为get和post(转)
- 大数据早报:简化数据分析界面,大数据平台Dataiku获2800万美元B轮融资(9.8)
- dplyr和data.table让你的数据分析事半功倍
- 数据绑定以及Container.DataItem的具体分析
- PHP 超全局变量 $_GET 和 $_POST 用于收集表单数据(form-data)。
- 数据绑定以及Container.DataItem几种方式与用法分析
- 数据绑定以及Container.DataItem几种方式与用法分析
- 通过Ajax post Json类型的数据到Controller
- jQuery使用ajax的post与get发送数据
- Ajax的post方法,模拟 从后台读取数据小demo
- Unrecognized token 'ename': was expecting ('true', 'false' or 'null')(ajax中data动态获取数据)
- ajax对一些没有接口的数据进行分析和添加方法
- 数据绑定以及Container.DataItem的具体分析
- 微阵列数据分析(Microarray Data Analysis)