ajaxForm(malsup)仅提交csrf_token而忽略表单中的其余输入字段

时间:2013-02-08 15:32:07

标签: jquery django ajaxform

我正在尝试使用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>

1 个答案:

答案 0 :(得分:0)

input必须提交name

E.g:

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