【发布时间】:2021-01-31 04:09:43
【问题描述】:
我用 ajax 调用 php 文件。在这个文件中,我有一个尝试捕获库的可能错误。
当我收到错误消息时,我会执行带有正确消息的 die 函数,但在 ajax 对象的成功方法中,我会收到一些带有错误消息的 html 表。我认为这条消息来自图书馆。
是否可以停止或清除此返回,并发送我自己的消息?
try {
$card_id = $stripe->customers->createSource($stripe_account['xxxx'],['source' => $card_token['id']]);
} catch (Exception $e) {
echo $e->getMessage(); //show message correctly
return "ERROR";
}
阿贾克斯:
$.ajax({
url: '/intranet/pms/includes/pay.php',
type: 'POST',
data: payment,
beforeSend: () => {
},
success: function(data){
console.log(data)
},
error: function (jqXHR, exception) {
console.log("ERROR")
}
});
在这种情况下,我从来没有得到错误字符串,只有一个字符串中的 html 表:
<br />
<font size='1'><table class='xdebug-error xe-uncaught-exception' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Uncaught (Status 402) (Request req_SSeWHpDt8WA4GV) The card number is not a valid credit card number.
thrown in C:\MAMP\htdocs\vendor\stripe\stripe-php\lib\Exception\ApiErrorException.php on line <i>38</i></th></tr>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Stripe\Exception\CardException: The card number is not a valid credit card number. in C:\MAMP\htdocs\vendor\stripe\stripe-php\lib\Exception\ApiErrorException.php on line <i>38</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.4018</td><td bgcolor='#eeeeec' align='right'>404976</td><td bgcolor='#eeeeec'>{main}( )</td>
总是在成功的 ajax 方法中接收此数据,从不出错..
【问题讨论】:
-
欢迎来到 Snack Overflow,请编辑您的问题并显示您的 AJAX 调用以及正确格式化您的 HTML 块。请删除任何不必要的代码标记,以便我们更容易看到发生了什么。谢谢。
-
谢谢!在这种情况下,html 块是一个控制台字符串,对于问题来说并不重要。
标签: php ajax stripe-payments