User "Status" Button in php codeigniter with ajax.
Hot to set user Active and Deactive Button in php Codeigniter with Ajax and Bootstrap.
Controller Code:
public function change_user_status($par = NULL)
{
$this->model_name->user_status($par);
}
{
$this->model_name->user_status($par);
}
Model Code:
function user_status($st)
{
if ($st == "true")
{
$this->db
->set('status', "Active")
->where('user_id', $_POST['id'])
->update('model_name');
}
else
{
$this->db
->set('status', "Deactice")
->where('user_id', $_POST['id'])
->update('model_name');
}
}
{
if ($st == "true")
{
$this->db
->set('status', "Active")
->where('user_id', $_POST['id'])
->update('model_name');
}
else
{
$this->db
->set('status', "Deactice")
->where('user_id', $_POST['id'])
->update('model_name');
}
}
View Page Code:
Paste this script on your vire page as same :
$(document).on("click",".status",function(){
var ida = $(this).parent().attr('id');
if($(this).prop("checked") == true){
$.ajax({
url:'user/change_user_status/true',
type:'post',
data:'id='+ida,
success:function(){
}
});
}
else if($(this).prop("checked") == false){
$.ajax({
url:'user/change_user_status/false',
type:'post',
data:'id='+ida,
success:function(){
}
});
}
});
var ida = $(this).parent().attr('id');
if($(this).prop("checked") == true){
$.ajax({
url:'user/change_user_status/true',
type:'post',
data:'id='+ida,
success:function(){
}
});
}
else if($(this).prop("checked") == false){
$.ajax({
url:'user/change_user_status/false',
type:'post',
data:'id='+ida,
success:function(){
}
});
}
});
Nice It work very smoothly
ReplyDeletenice tutorial
ReplyDeletewhat is the datatype of column 'status'?
ReplyDeleteEnum
Delete1 / 0
nice coding easily understand it. thank u
ReplyDeletei Got a Notice
ReplyDeleteUndefined property on console
Thanks for the tips.
ReplyDeleteSee Coding | Learn More | Improve knowledge
PHP, CSS, Magento, WordPress, JavaScript, jQuery related simple coding solutions
Thank you For This Tutorial
ReplyDeleteThank you, I appreciate that I getting a lot of good and reliable information from your post. Thanks for sharing such kind of nice and wonderful post.
ReplyDeletePhp Web Development Company Bangalore | Hire Website Developer India | Internet Marketing Company in Bangalore | Website Developers Bangalore
Very useful code for PHP application using code igniter.
ReplyDelete