繁体   English   中英

如何在Python Flask中使用Ajax

[英]how to use Ajax with Python flask

我已经使用Jquery编写了AJAX脚本。 当我调试脚本时,我注意到它没有通过“成功”和“错误”,但是确实存在。

这是JQuery代码

$(document).ready(function(){

    $('#report-submit').click(function() {
        alert('inside click');

        $.ajax({

            url: '/admin/file/start/rerun_reports/',
            //data: $i('form').serialize(),
            type: 'POST',
            success: function(response) {
                //alert(response);
                console.log("it works..................");
                console.log(response);
                $("#log-results").html(response);
            },
            error: function(error) {
                console.log(error);
            }
        });
    });

});

但是,当我提交按钮时,我没有Ajax就将数据发送到浏览器。

这是HTML代码

<form method="POST" action="/admin/file/start/rerun_reports/">
                <input name="_csrf_token" type=hidden value="{{ csrf_token() }}">
                <input class="btn btn-danger btn-lg" id="report-submit"
                    type="submit" value="submit">

            </form>

在这里我将数据发送到浏览器

return render_template('tools.html', data = json.dumps(start.logdata))

打印状态码时。 我收到403 error

您张贴thruogh html submit form ,并通过AJAX 。所以,如果你想POST通过AJAX .Change type='button'一样

<input class="btn btn-danger btn-lg" id="report-submit"
                type="submit" value="submit">

<input class="btn btn-danger btn-lg" id="report-submit"
                type="button" value="submit"> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM