加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ajax post data数据传值分析

发布时间:2020-12-16 02:00:54 所属栏目:百科 来源:网络整理
导读:今天在看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 i

今天在看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">&nbsp;<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}的形式,还有这样的一种 强大的数据处理方式。

希望大家都好好用用!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读