如何使用PHP发送服务器的错误响应? [英] How to send a server error response using php?
问题描述
一旦用户点击的删除按钮的我的jQuery脚本要求服务器删除选定的项目。
现在我希望我的 PHP 脚本发送成功或错误响应。
是否有可能为触发错误回调的情况下,该项目不能删除?
感谢
我jQuery的code:
$。阿贾克斯({
类型:后,
网址:myAjax.php
数据类型:文本,
数据: {
一些:数据
},
错误:函数(请求,错误)
{
//告诉用户为什么他不能删除该项目
//超时,没有找到......
},
成功:函数(响应)
{
//告诉该项目已被删除的用户
//隐藏项目
}
);
标题(HTTP / 1.0 404未找到);
头(HTTP,真实,500); // 500内部服务器错误
//等等等等。
查看头()获得更多的选择。 C $ CS所有的HTTP错误$可供使用。
相关问题:<一href="http://stackoverflow.com/questions/407651/how-do-you-trigger-the-error-callback-in-a-jquery-ajax-call-using-asp-net-mvc">http://stackoverflow.com/questions/407651/how-do-you-trigger-the-error-callback-in-a-jquery-ajax-call-using-asp-net-mvc
As soon as the user clicks the delete button my jQuery script asks the server to delete the selected item.
Now I want my php script to send a success or an error response.
Is it possible to fire the error callback in case the item could not be deleted?
Thanks
my jQuery code:
$.ajax({
type: "post",
url: "myAjax.php" ,
dataType: "text",
data: {
some:data
},
error: function(request,error)
{
// tell the user why he couldn't delete the item
// timeout , item not found ...
},
success: function ( response )
{
// tell the user that the item was deleted
// hide the item
}
);
header("HTTP/1.0 404 Not Found");
header('HTTP', true, 500); // 500 internal server error
// etc etc..
Check out header() for more options. All the HTTP error codes are available for use.
Related question: http://stackoverflow.com/questions/407651/how-do-you-trigger-the-error-callback-in-a-jquery-ajax-call-using-asp-net-mvc
这篇关于如何使用PHP发送服务器的错误响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!