Created
February 14, 2013 07:46
-
-
Save huglester/4951195 to your computer and use it in GitHub Desktop.
jQuery examples
This file contains hidden or 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
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