0

我有以下表格

<form id="reportcriteriaform">
   <div id="reportdialog_dialog" title="New Report" link="/newreport" class="modal show fade in" style="overflow:hidden;text-align:center;" aria-hidden="false">
      <div class="modal-header">
         WI's Resolved Report
      </div>
      <div class="modal-body">
         <div class="row-fluid">
            <div class="span6">
               <!-- Main report criteria fields go here -->            
               <div id="reportStartDate_row" class="control-group text-left">
                  <label class="control-label bold" for="reportStartDate"> <label for="reportStartDate">Start Date</label> </label> 
                  <div class="controls">
                     <div class="input-append date datepicker control-group" data-date-format="dd-M-yyyy">     
                        <input type="text" id="reportStartDate" name="reportStartDate" data-date-format="dd-M-yyyy" bs-datepicker="" class="input-large" value="">
                        <span class="add-on"><i class="icon-th" id="fromBtn"></i></span>
                     </div>
                  </div>
               </div>
               <div id="reportEndDate_row" class="control-group text-left">
                  <label class="control-label bold" for="reportEndDate"> <label for="reportEndDate">End Date</label> </label> 
                  <div class="controls">
                     <div class="input-append date datepicker control-group" data-date-format="dd-M-yyyy">     
                        <input type="text" id="reportEndDate" name="reportEndDate" data-date-format="dd-M-yyyy" bs-datepicker="" class="input-large" value="">
                        <span class="add-on"><i class="icon-th" id="fromBtn"></i></span>
                     </div>
                  </div>
               </div>
               <!-- Maultiselect box goes here -->                     
            </div>
            <div class="span6">
               <p>
                  <button type="button" name="runQuery" id="runQuery" class="btn btn-mini btn-primary " value="">Run Query</button>
               </p>
               <p>
                  <button type="button" name="close" id="close" class="btn btn-mini btn-primary " value="">Close</button>
               </p>
            </div>
         </div>
      </div>
   </div>
</form>

当我使用以下 ajax 调用提交它时,我在 request.data 或 request.form 中看不到任何数据

$.ajax({
    url: '/newreport',
            type:'POST',
    data:$('#reportcriteriaform').serialize(),  
    dataType: 'text/html',             
    success: function(data) {
                       //   Success stuff           
        }
});

新报告.py

from flask import render_template, request, session
    def post(self):
            request.data //This is empty string
            request.form //This is empty dictionary

            #Other stuff
4

1 回答 1

0

在ajax调用它应该像

type:'POST'

您缺少引号。

并且还按照标准数据类型提及数据"text/html"类型。(虽然不会引起问题,但是按照标准规范保持代码的良好做法)

于 2013-09-13T12:20:03.813 回答