javascript - 如何在我的 JS 代码中使用 flask.Response?
问题描述
我已经尝试了一段时间,但我未能设法从我的后端、我的前端获得返回值。
这是我的代码:
def add_New_Form():
resp = Response("something") #Note that the response value is a string
return resp
而且我希望能够在我的前端使用它(我正在使用 Vue)。我不能 jsonify resp
,因为 Response 不是 jsonifyable。我试过了:
var name = this.$http.post(*My request here*)
但这并不像我期望的那样工作。
提前致谢。
解决方案
你永远不会处理响应。当您使用this.$http
which时,vue-resource
您的请求可能会返回一个Promise
,然后您可以从中链接:
this.$http.post(*My request here*)
.then( response => {
console.log(response.data) // it's your string
})
推荐阅读
- javascript - 即使测试表明它们确实有效,firestore 规则也不起作用
- python - 如何在 Flask 1.0.4 中启用/配置 Jinja 行语句?
- typescript - 如何将“const asserted”变量传递给接受不太严格参数的函数
- azure - IIS 网站 URL 更改后的 Azure Devops 连接\构建代理问题
- session - Vapor 4 中的会话到期
- mongodb - MongoDB 数据聚合帮助
- android - 如何计算和设置 TextView 的正确文本大小?
- reactjs - 如何在 kepler.gl react.js 中切换图层可见性?
- c++ - 如何调用 MinGW gdb 中的函数?
- rust - 切换依赖箱功能的功能