ThinkPHP combines JQeury to implement POST data submission

Source: Internet
Author: User
Do I need to re-open the page to modify the website background data? No, use the following method to implement: html code: & lt; tablename & quot; unit & quot; border1 & gt; & lt; volistname & quot; u_list & quot; id & quot ;...

Do I need to re-open the page to modify the website background data? No, use the following method to implement it:

Html code:

  1. // Use the ID here to obtain the ID field in the data table
  2. {$ Vo. u_name}
  3.  
  4. {$ Vo. href}
  5.  
  6. [Delete]
  7.  
  8.  
  9.  
  10.  
  11. {$ Page} 
  12.  
  13.  

JQuery code:

  1. $ ("Tr> td"). dblclick (function (){
  2. Var inval = optional (this).html (); // obtain the original content
  3. Var inname = $ (this). attr ("name"); // Obtain the name value in the html code, that is, the field in the data table.
  4. Var inid = $ (this). parents (). attr ("id"); // obtain the ID of the data to be modified
  5. // Alert (inval );
  6. Certificate (this).html (" "); // Put the original content here
  7. $ ("# Edit"). focus (). live ("blur", function (){
  8. Var editval = $ (this). val ();
  9. $ (This). parents ("td" pai.html (editval );
  10. $. Post ("save", {id: inid, ziduan: inname, val: editval}); // submit data to Action through the POST method in the AJAX method of JQ
  11. });
  12. });

The Action code in ThinkPHP:

  1. Calss UnitAction extends Action {
  2. Function save (){
  3. $ Id = $ _ POST ['id'];
  4. $ Ziduan =$ _ POST ['ziduany'];
  5. $ Val = $ _ POST ['Val'];
  6. $ U_info = M ('unit ');
  7. $ U_info-> where ('Id = '. $ id)-> setField ($ ziduan, $ val)-> save ();
  8. }
  9. }
  10. ?>

A low-level error occurs during processing, that is, in the final Action:

  1. Calss UnitAction extends Action {
  2. Function save (){
  3. $ Id = $ _ POST ['id'];
  4. $ Data ['U _ name'] =$ _ POST ['U _ name'];
  5. $ Data ['href '] = $ _ POST ['href'];
  6. $ U_info = M ('unit ');
  7. $ U_info-> where ('Id = '. $ id)-> save ($ data );
  8. }
  9. }
  10. ?>

I replaced the specific field value so that I could not modify it. Fortunately, I found this error in time and corrected it. I recorded it for reference.

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.