【问题标题】:ajaxForm(malsup) submitting only csrf_token while ignoring rest of the input fields in the formajaxForm(malsup) 仅提交 csrf_token 而忽略表单中的其余输入字段
【发布时间】:2013-01-24 10:02:23
【问题描述】:

我正在尝试使用 ajaxForm 插件向 django Web 服务器应用程序提交表单。

问题

单击 addProductBtn 时,仅将以下内容发送到服务器: csrfmiddlewaretoken=cbREYGKpMgjBDyTvQ5GcB6xYbLZFhHH2

所有其他输入字段都被忽略。我错过了什么?

//easy_add_product.js

function getAjaxFormOptions(){
var options = {
        target: '#result',
        beforeSubmit: showRequest,
        success: showResponse,
        dataType: 'json'
};
return options;
}

function showRequest(formData, jqForm, options) {
var queryString = $.param(formData);
alert('query string: ' + queryString);
return true;
}

function showResponse(...){...}

$( function() {
  var options = getAjaxFormOptions();
  $('#add-product-form').ajaxForm(options);
} );

easy_add_product.html

<head>
     <script src="http://code.jquery.com/jquery-1.8.3.js" > </script>
     <script src="{{STATIC_URL}}js/plugins/jquery.form.js"></script>
     <script src="{{STATIC_URL}}js/easy_add_product.js"> </script>
  </head>
<form id="add-product-form" method="post" action='/pi/product/add_ajax' enctype="multipart/form-data">
  {% csrf_token %}
  <fieldset id="add-product-fs"> 
  <legend> Product Information </legend>
  <ul>   
<li>
     <label for='name'>Product Name <span class='required'>*</span> </label>
 <input type='text' required title='Product name is required' id='name' />
    </li>
     <li>
<label for='category'> Product Category</label>
    <input type='text' id='category' placeholder='dts_4ch' />
    </li> </ul>
   <input type='submit' id="addProductBtn" class="yui3-button formSubmitBtn"  value="Submit" />
 </form>

【问题讨论】:

    标签: jquery django ajaxform


    【解决方案1】:

    inputs 必须有names 才能提交。

    例如:

    <input type='text' required title='Product name is required' id='name' name="name" />
    

    【讨论】:

      猜你喜欢
      • 2011-05-06
      • 2021-09-08
      • 2011-12-11
      • 1970-01-01
      • 2020-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-01
      相关资源
      最近更新 更多