PHP Ajax enables real-time table editing and phpajax real-time table editing.
If we can operate all the data in a table on this page, it would be cool to use it )!
You can use Ajax to implement this function. I will post the demo I wrote below. Haha. I'm used to the TP framework (3.2.
The first part is the HTML code:
<! DOCTYPE html>
The following is the code in the controller:
<? Php namespace Home \ Controller; use Think \ Controller; class AjaxController extends Controller {public function index () {$ tab = M ('table '); $ tablist = $ tab-> select (); $ this-> assign ('tablist', $ tablist); $ this-> display ();} public function del () {$ map ['id'] =_ _ POST ['id']; $ tab = M ('table'); $ info = $ tab-> where ($ map) -> delete (); if ($ info) {$ this-> ajaxReturn ("deleted successfully ");} else {$ this-> ajaxReturn ("failed to delete") ;}} public function add () {$ map ['tab1'] = $ _ POST ['Post _ files'] ['clo _ 0']; $ map ['tab2'] = $ _ POST ['Post _ files'] ['clo _ 1']; $ map ['tab3'] = $ _ POST ['Post _ files'] ['clo _ 2']; $ map ['tab4'] = $ _ POST ['Post _ files'] ['clo _ 3']; $ tab = M ('table '); $ res = $ tab-> add ($ map); if ($ res) {$ this-> ajaxReturn ("added successfully ");} else {$ this-> ajaxReturn ("failed to add") ;}} public function edit () {$ id = $ _ POST ['id']; $ map ['tab1'] = $ _ POST ['Post _ files'] ['clo _ 1']; $ map ['tab2'] = $ _ POST ['Post _ files'] ['clo _ 2']; $ map ['tab3'] = $ _ POST ['Post _ files'] ['clo _ 3']; $ map ['tab4'] = $ _ POST ['Post _ files'] ['clo _ 4']; // dump ($ map); exit; $ tab = M ('table'); $ res = $ tab-> where ('Id = '. $ id)-> save ($ map); if ($ res) {$ this-> ajaxReturn ("updated successfully ");} else {$ this-> ajaxReturn ("update failed ");}}}
The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!