I'm making a bingo style game. I generate cards with images in each cell. When a cell is clicked I want to change the cell image based on the response to an ajax call. I have tried many variations of the following code without success:
$(document).ready(function () {
$('img').click(function (event) {
var src = $(this).attr("src");
var id = $(this).attr("id");
var ref = src +' ' + id;
if(src == 'cards/cardon.gif') return false;
$.ajax({
url: "checkBingo.php",
type: "POST",
data:{"ref":ref},
success: function (response) {
alert(response);
if(response.indexOf('Strike') != -1) $(this).attr('src', 'images/cross.png');
else if (src != 'images/bingo.jpeg') $(this).attr('src', 'cards/cardon.gif');
}
})
return false;
})
});
I know the response contains 'Strike' but neither of the images is being set. Please help
I've tried many variations including setting a var based on response.indexOf('Strike') != -1) and then swapping the images outside the ajax call