【问题标题】:How can I use the flask.Response in my JS code?如何在我的 JS 代码中使用 flask.Response?
【发布时间】:2019-02-06 00:01:41
【问题描述】:

我已经尝试了一段时间,但我没能从我的后端、我的前端获得返回值。

这是我的代码:

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*)

但这并不像我期望的那样工作。

提前致谢。

【问题讨论】:

    标签: javascript python json flask vue.js


    【解决方案1】:

    您永远不会处理响应。当您使用this.$http(很可能是vue-resource)时,您的请求会返回一个Promise,然后您可以从中链接:

    this.$http.post(*My request here*)
      .then( response => {
          console.log(response.data) // it's your string
      })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-12
      • 1970-01-01
      • 2018-05-03
      • 1970-01-01
      • 1970-01-01
      • 2015-07-14
      • 2022-11-03
      • 1970-01-01
      相关资源
      最近更新 更多