我正在使用此功能:
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()
}
}
});
}
这就是我想要回归
<WebMethod()> _
Public Shared Function ProcessCard(ByVal Token As String) As Boolean
Return False
End Function
即使第一个警报(响应)确实显示为false,我也无法获得else语句。 if(response = true)始终显示警告(&#34; True&#34;)。我不是很擅长java,所以不确定如何正确阅读响应。我尝试过数据类型:&#34; text&#34;同样。
我想确保在if else语句中正确读取true或false。
答案 0 :(得分:0)
您应该在if语句中使用javascript比较运算符==或===:
if (response === true) {
....
}