类似facebook无刷新ajax更新
类似facebook无刷新ajax更新
XML/HTML Code
- <script type="text/javascript">
- $(document).ready(function()
- {
- $('.edit_link').click(function()
- {
- $('.text_wrapper').hide();
- var data=$('.text_wrapper').html();
- $('.edit').show();
- $('.editbox').html(data);
- $('.editbox').focus();
- });
- $(".editbox").mouseup(function()
- {
- return false
- });
- $(".editbox").change(function()
- {
- $('.edit').hide();
- var boxval = $(".editbox").val();
- var dataString = 'data='+ boxval;
- $.ajax({
- type: "POST",
- url: "update_profile_ajax.php",
- data: dataString,
- cache: false,
- success: function(html)
- {
- $('.text_wrapper').html(boxval);
- $('.text_wrapper').show();
- }
- });
- });
- $(document).mouseup(function()
- {
- $('.edit').hide();
- $('.text_wrapper').show();
- });
- });
- </script>
- <style type="text/css">
- body
- {
- font-family:Arial, Helvetica, sans-serif;
- font-size:12px;
- }
- .mainbox
- {
- width:250px;
- margin:50px;
- }
- .text_wrapper
- {
- border:solid 1px #0099CC;
- padding:5px;
- width:187px;
- }
- .edit_link
- {
- float:right
- }
- .editbox
- {
- overflow: hidden; height: 61px;border:solid 1px #0099CC; width:190px; font-size:12px;font-family:Arial, Helvetica, sans-serif; padding:5px
- }
- </style>
- <div class="mainbox">
- <a href="#" class="edit_link" title="Edit">Edit</a>
- <?php
- include("db.php");
- $sql=mysql_query("select email from users where user_id='1'");
- $row=mysql_fetch_array($sql);
- $profile=$row['email'];
- ?>
- <div class="text_wrapper" style=""><?php echo $profile; ?></div>
- <div class="edit" style="display:none"><textarea class="editbox" cols="23" rows="3" name="profile_box"></textarea></div>
- </div>
update_profile_ajax.php
PHP Code
- <?php
- if($_POST['data'])
- {
- $data=$_POST['data'];
- $data = mysql_escape_String($data);
- $sql = "update users set email='$data' where user_id='1'";
- mysql_query( $sql);
- }
- ?>
相关推荐
周公周金桥 2020-09-06
大象从不倒下 2020-07-31
AlisaClass 2020-07-19
MaureenChen 2020-04-21
xingguanghai 2020-03-13
teresalxm 2020-02-18
木四小哥 2013-05-14
SoShellon 2013-06-01
Simagle 2013-05-31
羽化大刀Chrome 2013-05-31
waterv 2020-01-08
LutosX 2013-07-29
vanturman 2013-06-27
wutongyuq 2013-04-12
luoqu 2013-04-10
today0 2020-09-22
89520292 2020-09-18
bigname 2020-08-25