2015-04-02 125 views
0

我已經寫過,使用Jquery的AJAX腳本。當我通過腳本進行調試時,我注意到它沒有經過「成功」和「錯誤」但它存在。如何在Python中使用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); 
      } 
     }); 
    }); 

}); 

然而,當我提交按鈕,我得到的數據,瀏覽器,而阿賈克斯。

下面是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

+0

我猜你使用Flask- WTF for CSRF? – nathancahill 2015-04-02 20:43:53

+0

我已將CSRF令牌添加到html表單。還要別的嗎? – newday 2015-04-02 21:52:54

+0

如果你使用Flask-WTF,你可以寫'{{form.csft_token}}' – nathancahill 2015-04-02 22:21:34

回答

0

您通過AJAX。所以發佈thruogh html submit form也如果通過AJAXPOST .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"> 
+0

謝謝,我試過了,但沒有奏效。 – newday 2015-04-02 17:03:11

+0

所以它不通過'ajax'發佈? – itzMEonTV 2015-04-02 17:04:46

+0

當我嘗試打印狀態碼時,出現NetworkError:403 FORBIDDEN – newday 2015-04-02 17:31:14