I have the following code
$(document).ready(function(){
// class exists
if($('.delete').length) {
// add click handler
$('.delete').click(function(){
// ask for confirmation
var result = confirm('Are you sure you want to delete this?');
var vid = $(this).attr('id');
var row = $(this).parents('tr');
// do ajax request
if(result) {
$.ajax({
type:"POST",
url:"delete_joke.php",
data:{id:vid,garbage:'FG9g543hfh'},
dataType: "json",
success:function(response){
// hide table row on success
if(response == "true") {
row.fadeOut();
$('#errors').show();
$('#errors').html( '<div class="message green"> Successfully deleted!<img src="http://puppetweb.ca/play/views/admin/gfx/icon-close.gif" alt="Close this item" /> </div>' ).show();
}else{
$('#errors').show();
$('#errors').html( '<div class="message red"> Error deleting. <img src="http://puppetweb.ca/play/views/admin/gfx/icon-close.gif" alt="Close this item" /> </div>' ).show();
}
}
});
}
return false;
});
}
});
And it works up until the part where I want to show the success, I have the php script print “true” on success and “false” on error, and if I do alert(response) it shows the word true. But it is displaying the Error deleting on success and Error deleting on error?
Any help?
Try replacing
if(response == "true")withif(response)if you are sure it is returning true/false.To check the type of data response is, try
alert(typeof response)and see what it shows.Edit:
Since you mention data type as JSON, make sure you return a valid response and set the content type to json in response.
If your
jsonreturn is{"status":true}then you should useif(response.status)