js:

$.ajax({
            type: "POST",
            url: 'post.php',
            data: serialNumber + "&getSerialNumber=" + 1,
            dataType: 'json',
            success: function(data, textStatus, jqXHR) {
                console.log("SUCCESS");
            },
            error: function(jqXHR, textStatus, errorThrown) {
                console.log("ERROR");
            }
        });

php:

if($product->GetSerial($serial)) {
    $productInfo = $product->GetSerial($serial)->first();
    header('Content-Type: application/json', true, 200);
    die(json_encode(["error"=> false, "message"=> "Successfully got serial number"]));
} else {
    header('Content-Type: application/json', true, 400);
    die(json_encode(["error"=> true, "message"=> "failed to get serial number"]));
}
header('Content-Type: application/json', true, 200);

可以返回规定的错误码。

相关文章:

  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
  • 2022-03-09
  • 2021-12-13
  • 2022-12-23
猜你喜欢
  • 2021-11-12
  • 2021-09-21
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
相关资源
相似解决方案