本文介绍了如何获得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?
发布评论