I have been all over Stack Overflow looking for a solution and none seem to work.
I cannot seem to figure out the issue. I have a button inside a <td>
and on clicking it I want to make an AJAX call to update a database and upon success of that AJAX call I want to update the class of the <td>
to mark the button as clicked.
I have tried var that = this;
in the function. I've tried context: this,
in the callback.
function setScoreA(event,candidate,rubric,category,score){
var author = document.getElementById("author").value;
if(author != ""){
$.ajax({
context: this,
type: "POST",
url: "stressBoardUpdate.php",
data: "candidate="+candidate+"&category="+category+"&score="+score+"&author="+author,
success: function(){
$(that).parent('td').siblings().removeClass('isScore');
$(that).parent('td').addClass('isScore');
}
});
}else{
alert("Author must contain something...");
}
}
Here is how the function would get invoked.
<input type="button" "="" value="5" onclick="setScoreA('Stress Board','Y235','Stress Board Rubric','Handled Stress','5');">
var that = this
? And how is this function called? Post the event handler for the click as well.var author ...
$("#the-id")
.var that = $(this);
then in your ajax call:that.parent('td')...
setScoreA()
in a way that sets thethis
value as you would like. Please show us howsetScoreA()
is called.