正如你从标题中看到的那样,我想弹出一个警报,显示"信用卡号无效。"
我目前正在使用alert(data.responseText);但显示"当信用卡号与订阅关联时,无法将其更新为不受支持的卡类型。
此商户帐户不接受信用卡号类型。
信用卡号无效。
{"success":"false","message":"信用卡号无效"}"
有没有办法只显示"信用卡号无效"部分。
如果我使用警报(data.Message));给出"未定义"和警报(数据);给出"[object object]"。
谢谢你的帮助。
var data = {
"action": "checkout"
};
data = $('#checkout_form').serialize() + "&" + $.param(data);
$.ajax({
type: "POST",
dataType: "json",
url: "inc/placeorder.php", //Relative or absolute path to response.php file
data: data,
success: function(data) {
if(data["success"] == 'true'){
$("#placeorder").attr("disabled",false);
$(".payment_loader").fadeOut("slow").hide();
$('#checkout_form').trigger("reset");
window.location = "order_success.php";
}
if(data["success"] == 'false'){
$("#placeorder").attr("disabled",true);
$(".payment_loader").fadeOut("slow").hide();
$('#subscribe_response').html(data['message']);
alert(data.responseText);
}
},
error: function(data, status){
alert(data);
console.log("error", data.responseText);
console.log("error", status.responseText);
}
});
}else{
return false;
}
});
编辑
这就是抛出的错误。
} else {
foreach ($result->errors->deepAll() as $error) {
$errorFound = $error->message . "<br />";
echo $errorFound;
}
$response = array("success" => "false", "message" => $errorFound);
return $response;
exit;
}
实际上,您在ajax请求中设置了响应类型"json",但在"json中"没有得到响应。使用php脚本中的json_encode函数返回json响应
return json_encode(response);
然后提醒
alert(data.message);