PHP触发AJAX错误代码而不使用数组 [英] PHP trigger AJAX error code without using array

查看:85
本文介绍了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,以此类推.您可以看到参考这应该是您要使用的干净的解决方案.

    This should be the clean solution you are going for.

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

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