PHP在不使用数组的情况下触发AJAX错误代码 [英] PHP trigger AJAX error code without using array

查看:35
本文介绍了PHP在不使用数组的情况下触发AJAX错误代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够获得一个通过 AJAX 调用的 PHP 脚本,以返回 jQuery AJAX 处理程序 error: 将处理的错误代码.我不想使用 JSON 数组 - 我想保持它尽可能干净.有人能指出我正确的方向吗?

I want to be able to get a PHP script called via AJAX to return with an error code that the jQuery AJAX handler error: will handle. I don't want to use a JSON array - I'd like to keep it as clean as possible. Can someone point me in the right direction?

谢谢,

詹姆斯

推荐答案

如果要触发 AJAX 错误处理程序,只需传回 200 以外的内容!试试这个:

If you want to trigger the AJAX error handler, just pass back something other than a 200! Try this:

<?php
  header("HTTP/1.0 404 Not Found");
  exit();
?>

只要记住做两件事:

  1. 尝试发送正确的错误代码以符合 HTTP 方法.即如果您的页面抛出错误,那么您应该返回 500 等.您可以查看参考 在 w3.org 网站上.
  2. 确保在除空格之外的任何其他内容之前发送标头.

这应该是您想要的干净解决方案.

This should be the clean solution you are going for.

这篇关于PHP在不使用数组的情况下触发AJAX错误代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆