本文介绍了在邮递员到AJAX中显示的输出REST API状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 在Postman中,我可以成功地与我的REST API通信。我可以将我的API服务器置于各种人工状态,分别代表2xx,4xx&我可以在邮递员中成功查看的5xx错误如下:In Postman, I can successfully communicate with my REST API. I can put my API server in various artificial states to represent 2xx, 4xx & 5xx errors which I can successfully view in Postman as follows: Postman能够收集此信息,而不管API服务器是否正在运行&Postman is able to collect this info, regardless of whether or not the API server is running & it appears to be a generic status response, vs. a response that the API app produces.我的问题是,如何将其输出到console.log()在我的Javascript应用程序中?My question is, how do I output this into a console.log() in my Javascript App?在我的实例中,我想在表单提交后端的AJAX函数中输出状态:In my instance, I want to output the status inside an AJAX function at the backend of a form submit:$.ajax(settings).done(function(response, jqXHR, data) { console.log("Return Code: " + data.status); }) .fail(function(jqXHR, textStatus, errorThrown) { console.log("Return Code: " + ??? ); });});成功后我的data.status可以正常工作,但是大概有一个变量可以My data.status works fine when I get a success, but presumably there is a variable that I can tap into that is the generic status message?推荐答案您可以从状态获取返回的状态代码。 jqXHR 对象的属性:You can get the returned status code from the status property of the jqXHR object:.fail(function(jqXHR, textStatus, errorThrown) { console.log("Return Code: " + jqXHR.status);}); 工作示例 这篇关于在邮递员到AJAX中显示的输出REST API状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-21 02:50