今天在看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}的形式,还有这样的一种 强大的数据处理方式。
希望大家都好好用用! (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|