Ajax post data Value Transfer Analysis

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.