Implementation similar to Facebook without refreshing Ajax update _ajax related

Source: Internet
Author: User

Copy Code code as follows:

<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= "" rows= "3" name= "Profile_box" > </textarea></div>
</div>

update_profile_ajax.php
Copy Code code as follows:

<?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);
}
?>
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.