JSONify 返回奇怪的值

我想要做的是通过 AJAX 将 Python 中函数的结果返回给我的 javascript。目前,我在期待“真”或“假”时收到此响应


查询:


  var test = $.getJSON("/chk_chn", {

    name: channel_name

  });


  alert(test.toSource())

Python:


@app.route("/chk_chn")

def chk_chn_unique():

"""Checks a name against all existing Channels in a Channel List. Returns True if name is unique, False otherwise"""

name = request.args.get("name")

for channel in Channels:

    if channel.get_name() == name:

        return jsonify(result=False)

return jsonify(result=True)


达令说
浏览 142回答 3
3回答

BIG阳

您缺少回调函数,只是打印出请求对象。试试这个:$.getJSON('/chk_chn', { name: channel_name })    .done(function (data) {        console.log(data);    });

慕哥6287543

你有没有尝试过:return jsonify({result: True})
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python