您的位置:首页 > 其它

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

希望对大家有帮助
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: