Kevin Kevin - 2 months ago 6x
Ajax Question

ajax success: Function()

I am using this Function:

function ProcessToken(token) {
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
if (response = true) {
$form.find('.subscribe').html('Payment successful <i class="fa fa-check"></i>');
} else {
$form.find('.subscribe').html('Try again').prop('disabled', false);
$form.find('.payment-errors').text('Something went wrong, please try again.');




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.


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

if (response === true) {