ajax post data資料傳值分析

來源:互聯網
上載者:User

 今天在看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}的形式,還有這樣的一種 強大的資料處理方式。


       希望大家都好好用用!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.