当前位置:编程学习 > JAVA >>

ajax post data数据传值分析

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


       希望大家都好好用用!

补充:web前端 , JavaScript ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,