Today, when I was reading the opencart code, I saw a very strange way:
$. 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 = \ 'den den \ '], # payment-address select '),
DataType: 'json ',
BeforeSend: function (){
$ ('# Button-payment-address'). prop ('Disabled ', true );
$ ('# Button-payment-address '). after ('<span class = "wait"> & nbsp; </span> ');
},
Complete: function (){
$ ('# Button-payment-address'). prop ('Disabled ', false );
$ ('. Wait'). remove ();
},
Success: function (json ){
$ ('. Warning,. error'). remove ();
... N lines of code are omitted here
Data transmission parameters. This includes the values of all input type = text fields on the current page, input type = password fields, input type = checkbox, and radio, hidden, the values of the select field are passed. On the url Processing page, 'index. php? Route = checkout/payment_address/validate ', you can receive the value from ajax on the html page as follows:
$ This-> request-> post ['payment _ address'], here, payment_address is the <input type = "radio" name = "payment_address" value = "existing" id = "payment-address-existing" checked = "checked"/>.
Therefore, in addition to the {key: value} form, data transmission parameters also have such a powerful data processing method.
Hope everyone can use it!