Welcome Guest, Not a member yet? Register   Sign In
Need Help in Deletion of a Record using Jquery ....!!!
#1

[eluser]Zeeshan Rasool[/eluser]
Hi guys i need some help in jquery i want to delete a record using jquery its working fine in case of sucess but how can i put a check to find failure state. I dont want to delete a category which has a subcategory so it removes the record from listing and when i refresh page it shows again so is there any way to track the failure and show an error so that user get information that its attempt is not succeeded..?

Thanks in advance

Here is my code..
Code:
$(document).ready(function() {
$('a.delete').click(function(e) {
e.preventDefault();
var parent = $(this).parent();
//var user_id = parent.attr('id').replace('my_div_id','');
if(confirm('Are you sure to delete this record?')==true ){
var category_id = URL;
$.ajax({
type: 'get',
url: '<?php echo base_url(); ?>/cms/delete_category/'+category_id,
data: parent.attr('id').replace('my_div_id',''),
beforeSend: function() {
parent.animate({'backgroundColor':'#fb6c6c'},300);
},
success: function() {
parent.slideUp(300,function() {
parent.remove();
});
}
});}
});
});
#2

[eluser]umefarooq[/eluser]
first set your type:get to post because CI is not dealing with get have look on it

http://ellislab.com/codeigniter/user-gui...urity.html

and you are calling delete_category function of you controller.
#3

[eluser]Thorpe Obazee[/eluser]
Code:
success: function(message)

You can retrieve messages via the success callback. You can get the response which can either be an error or a success message.
#4

[eluser]umefarooq[/eluser]
also use firefox and firebug for ajax will help you to solve your problem,
#5

[eluser]Zeeshan Rasool[/eluser]
[quote author="umefarooq" date="1241443572"]first set your type:get to post because CI is not dealing with get have look on it

http://ellislab.com/codeigniter/user-gui...urity.html

and you are calling delete_category function of you controller.[/quote]

thanks guys, but i also tried this by setting get to post.yes it is controller function i
think when we are call
Code:
url: '<?php echo base_url(); ?>/admin/delete_category/'+aCars,
it done its work .
[quote author="bargainph" date="1241444573"]
Code:
success: function(message)

You can retrieve messages via the success callback. You can get the response which can either be an error or a success message.[/quote]

Also when i use success: function(message) its returns nothing in both cases means deletion or failure.
#6

[eluser]umefarooq[/eluser]
hi first check in your delete_category function if it is a function that you are getting aCars variable or not and echo it in that function than success: function(message) will work, it calling specific function or not if it is calling than you can do what ever you want also check url is proper or not.
#7

[eluser]Zeeshan Rasool[/eluser]
but deletion is working fine how ever i just need to put a check to detect whether deletion is successful or not..
#8

[eluser]umefarooq[/eluser]
if success echo 1 if fail echo 0 and then check here like after echo put die(); so it will not give more output

Code:
success: function(msg){
                   if(msg == 1)
                    alert( "Sussess " );
                   else
                   alert("Fail");
                }




Theme © iAndrew 2016 - Forum software by © MyBB