I have this snippet of AJAX code which is working correctly in the fact its updating my database, only once its done its not executing the rest of my code…
$(".getPoint").click(function()
{
var theid = $(this).attr("id");
var onlyID = theid.split("_");
var onlyID = onlyID[1];
var credoff = parseInt($(this).children('input.credoff:hidden').val());
$.ajax({
url: 'do.php',
type: 'POST',
data: "userID=" + onlyID + "&credoff=" + credoff,
success: function(data) {
if(data != "success1" && data != "success5") {
$("#" + theid).text(data);
}else{
$("#thediv_" + onlyID).fadeOut("slow");
$('#creditsBalance').fadeOut("slow");
newbalance = parseInt($('#creditsBalance').text());
if(data != "success5") {
newbalance = newbalance+credoff;
}else{
newbalance = newbalance+5;
}
alert ('hi');
$('#creditsBalance').text(newbalance);
$('#creditsBalance').fadeIn("slow");
$("#" + theid).text("Done");
}
},
beforeSend: function()
{
$("#" + theid).text("Working...");
},
error: function()
{
$("#" + theid).text("Failed...Click to Retry");
}
});
});
The line
if(data != "success5") {
newbalance = newbalance+credoff;
}else{
newbalance = newbalance+5;
}
alert ('hi');
Updates my DB but then I dont receive an alert, Is this enough code for anybody to see where im going wrong?
if you want to send the alert on success change your snippet like this
this way if it is ‘success5’ you will get your alert