如何获得HTTP状态code与jQuery?

编程入门 行业动态 更新时间:2024-10-10 05:24:58
本文介绍了如何获得HTTP状态code与jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我要检查,如果一个页面返回状态code 401这可能吗?

下面是我的尝试,但它只返回0。

$。阿贾克斯({     网址:HTTP://my-ip/test/test.php     数据: {},     完成:功能(XHR,状态文本){     警报(xhr.status);     } });

解决方案

这是可能与jQuery $。阿贾克斯()方法

$。阿贾克斯(的serverUrl,{    类型:OutageViewModel.Id()== 0? 邮报:PUT    数据:dataToSave,    状态code:{       200:功能(响应){          警报('1');          AfterSavedAll();       },       201:功能(响应){          警报('1');          AfterSavedAll();       },       400:功能(响应){          警报('1');          bootbox.alert('<跨度风格=颜色:红色;>错误,同时节省停运进入请检查< / SPAN>',函数(){});       },       404:功能(响应){          警报('1');          bootbox.alert('<跨度风格=颜色:红色;>错误,同时节省停运进入请检查< / SPAN>',函数(){});       }    },成功:函数(){       警报('1');    }, });

I want to check if a page returns the status code 401. Is this possible?

Here is my try, but it only returns 0.

$.ajax({ url: "my-ip/test/test.php", data: {}, complete: function(xhr, statusText){ alert(xhr.status); } });

解决方案

this is possible with jQuery $.ajax() method

$.ajax(serverUrl, { type: OutageViewModel.Id() == 0 ? "POST" : "PUT", data: dataToSave, statusCode: { 200: function (response) { alert('1'); AfterSavedAll(); }, 201: function (response) { alert('1'); AfterSavedAll(); }, 400: function (response) { alert('1'); bootbox.alert('<span style="color:Red;">Error While Saving Outage Entry Please Check</span>', function () { }); }, 404: function (response) { alert('1'); bootbox.alert('<span style="color:Red;">Error While Saving Outage Entry Please Check</span>', function () { }); } }, success: function () { alert('1'); }, });

更多推荐

如何获得HTTP状态code与jQuery?

本文发布于:2023-11-28 17:46:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643363.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何获得   状态   jQuery   HTTP   code

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!