-
-
Save dopsmain/f141f019db427a1a40f55b497cbfc19d to your computer and use it in GitHub Desktop.
Edit in place using ajax and contenteditable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// quit script if you aren't accessing it with ajax | |
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) == false){ | |
die(); | |
} | |
// include database class | |
include('database.class.php'); | |
// initialize database class | |
$db = new database('localhost','user','pass','db'); | |
// send the data to the database | |
$query = $db->query("UPDATE table SET content='".$_POST['content']."' WHERE id='".$_POST['id']."'"; | |
// if successful, echo true, else false | |
echo !!$query; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<section id="1"> | |
<p contenteditable="true"> | |
Some text here | |
</p> | |
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('p[contenteditable=true]').live('blur',function(){ | |
$.ajax({ | |
type:'POST', | |
url:'edit_item.php', | |
data:{ | |
content: $(this).text(), | |
id: $(this).parent().attr('id') | |
}, | |
success:function(msg){ | |
if(!msg){ | |
//console.error('update failure'); | |
alert('update failure'); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment