【问题标题】:python flask jquery get issuepython烧瓶jQuery得到问题
【发布时间】:2017-09-30 05:35:56
【问题描述】:

这个 Web 服务器问题的奥秘是什么。

这是我的代码,它在本地服务器上运行良好,但在 Web 服务器上它不起作用:

$.ajax({
      url: "/flask/templates/table.html",
      type: "get",
      data: {jsdata: $( "#select option:selected" ).text()},
      success: function(response) {
        $("#place_for_suggestions").html(response);

      },
      error: function(xhr) {
        // handle error
      }
    });

烧瓶一侧:

@FlaskApp2.route('/flask/templates/table.html', methods=['GET', 'POST'])
def table():

    modid = request.args.get('jsdata')

    print "Hello!!!!!!!!!!!!!!!!", modid 
    return render_template('table.html')

我尝试查看@FlaskApp2.route 中的任何活动,但我只看到静默!

这段代码有什么问题?

【问题讨论】:

  • 能不能看看浏览器发出的网络请求是什么,把请求数据贴在这里。
  • GET domen.com/flask/templates/table.html?jsdata=Data%20Air HTTP/1.1 主机:domen.com 连接:keep-alive 接受:/ X-Requested-With:XMLHttpRequest 用户代理:Mozilla/5.0 ( Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 Referer: domen.com/flask/rest Accept-Encoding: gzip, deflate Accept-Language: en-US,en;q=0.8饼干:__utma=259990281.1969885139.1506122487.1506122487.1506737103.2; __utmz=259990281.1506122487.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
  • 我有 404 错误!但是为什么???

标签: jquery python ajax flask


【解决方案1】:

methods=['GET','POST'] 的动词在匹配你的路由时区分大小写。所以在你的 .ajax 中使用method: 'GET' 而不是type: 'get'。在 jquery 的更高版本中,type 已被 method 取代。

【讨论】:

  • jQuery 确保方法 is uppercase 所以这里没有区别。
猜你喜欢
  • 1970-01-01
  • 2014-04-06
  • 2012-11-18
  • 2021-10-15
  • 1970-01-01
  • 1970-01-01
  • 2013-09-06
  • 2020-02-19
相关资源
最近更新 更多