What's wrong with this code? I'm not able to validate 'data':
$.post('http://localhost/do.php', function(data)
{
if (data == "success")
{
//do something... but this line never hit!
}
});
I also tried,
alert(data);
but got an empty alert box!
the do.php on success, echo's "success"
echo "success";
ok.. here is the complete original code:
<script type="text/javascript">
function confirm_delete(id)
{
var r=confirm("Are you sure you want to delete?");
if (r==true)
{
var path = "http://localhost/site/index.php/delete/" + id;
$.post(path, function(data)
{
if (data=='success')
{
$('#'+id).remove();
}
else
{
alert("Unable to delete, try again!");
}
});
}else
{
//cancel
}
}
//-->
</script>
In the HTML, there will be many posts with their respective id's in div, laid by php from database, somewhat like this:
<div id="1">
<div class='post'>Something</div>
<a href="#"><img src="styles/plugins/buttons/icons/cross.png" height="8" width="8" title="Remove" onclick="confirm_delete(1)"/></a>
</div>
<div id="2">
<div class='post'>Something</div>
<a href="#"><img src="styles/plugins/buttons/icons/cross.png" height="8" width="8" title="Remove" onclick="confirm_delete(2)"/></a>
</div>
<div id="3">
<div class='post'>Something</div>
<a href="#"><img src="styles/plugins/buttons/icons/cross.png" height="8" width="8" title="Remove" onclick="confirm_delete(3)"/></a>
</div>
In the php there is nothing now... it just prints success... i made it like that for testing.
echo "success";
When going to the linking directly, it printing "success". Is 'Data' a string? I mean is this correct?
if (data=='success')