Kevin Kevin - 4 months ago 12
Ajax Question

ajax success: Function()

I am using this Function:

function ProcessToken(token) {
$.ajax({
type: "POST",
url: "HomePage.aspx/ProcessCard",
data: '{Token: "' + token + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
failure: Failure,
success: function(R) {

var response = R.d
alert(response)
if (response = true) {
alert("True")
$form.find('.subscribe').html('Payment successful <i class="fa fa-check"></i>');
} else {
alert("False")
$form.find('.subscribe').html('Try again').prop('disabled', false);
$form.find('.payment-errors').text('Something went wrong, please try again.');
$form.find('.payment-errors').closest('.row').show()
}

}

});

}


This is what im trying to return

<WebMethod()> _
Public Shared Function ProcessCard(ByVal Token As String) As Boolean
Return False
End Function


I have not been able to get the else statement to occur even though the first alert(response) does show false. The if (response = true) always shows alert("True"). Im not very good at java so not sure how to read the response properly. Ive tried datatype: "text" as well.

Im wanting to make sure true or false is read properly in the if else statement.

Answer

You should use javascript comparison operators == or === in your if statement:

if (response === true) {
 ....
}