我正在寻找 Javascript 中的 http 状态代码列表。它们是否在任何实现中定义?
我查看了 XMLHttpRequest
,但只找到了 readyState
常量。
var xhr = new XMLHttpRequest();
console.log(xhr.DONE); //4
我正在寻找类似的东西
console.log(xhr.statusCodes.OK); //200
这显然不存在于 xhr 对象上。
最佳答案
对于 node.js,您可以使用模块 node-http-status ( github )。
这是一个例子:
var HttpStatus = require('http-status-codes');
response
.status(HttpStatus.OK)
.send('ok');
response
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.send({
error: HttpStatus.getStatusText(HttpStatus.INTERNAL_SERVER_ERROR)
});
关于javascript - 访问http状态码常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18765869/