Home>Article>Web Front-end> ajax combined with mysql database to achieve partial data refresh
This time I will bring you ajax combinationmysql databaseTo achieve partial data refresh, ajax combined with mysql database to achieve partial data refreshWhat are the precautions, the following is a practical case, one Get up and take a look.
Effect status: switch between status lock and non-lock by clicking on the lock status
1. Main program: 01.php imports smarty and mysql classes, and obtains the data import list template
getALL('users'); $smarty->assign('lists',$lists); $smarty->display('list.html'); ?>
2. The list template uses smarty Traverse the template data and display it, in which ajax is called to change the lock status
用户权限展示表
uid | 用户名 | 密码 | 锁定状态 | 角色 | ||
---|---|---|---|---|---|---|
{$list.uid} | {$list.username} | {$list.password} | {if $list.is_lock==1}锁定 | {else}取消锁定 | {/if} {if $list.role==1}管理员 | {else}编辑者 | {/if}
3.ajax response script, receives the data passed by ajax through the get method, changes the database content and The response text is sent back to the js script
update('users',"is_lock=$lock","uid=$uid"); if($result){ echo true; }else{ echo false; } ?>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
Detailed graphic explanation of ajax implementation of dynamic pie charts and column charts
The above is the detailed content of ajax combined with mysql database to achieve partial data refresh. For more information, please follow other related articles on the PHP Chinese website!