Skip to content

Instantly share code, notes, and snippets.

@huglester
Created February 14, 2013 07:46
Show Gist options
  • Save huglester/4951195 to your computer and use it in GitHub Desktop.
Save huglester/4951195 to your computer and use it in GitHub Desktop.
jQuery examples
var savehelp = {
init: function() {
$('.save-help').on('click', function(e){
e.preventDefault();
var $this = $(this);
var id = $this.closest('tr').find('textarea').attr('id');
var text = $this.closest('tr').find('textarea').attr('value');
console.log( { id: id, text: text } );
$.ajax({
url: base_url + '/admin/settings/savehelp',
data: { id: id, text: text },
type: "POST",
success: function(data) {
console.log(data);
if(data == 'error')
{
$this.after('<div class="error">Error</div>');
}
else
{
$this.after('<div class="success">Success</div>');
}
}
})
});
}
}
savehelp.init();
---
public function post_savehelp()
{
if( Request::ajax() )
{
$affected = DB::table('help')
->where('id', '=', Input::get('id'))
->update( array('text' => Input::get('text')) );
if($affected == 0)
{
echo 'error';
}
else
{
echo 'ok';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment