我正在尝试使用ajaxForm插件向django web服务器应用程序提交表单。
问题
单击addProductBtn时,仅向服务器发送以下内容:csrfmiddlewaretoken=cbREYGKpMgjBDyTvQ5GcB6xYbLZFhHH2
忽略所有其他输入字段。我错过了什么?
//easy_ad_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_ad_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>
input
s必须有name
s才能提交。
例如:
<input type='text' required title='Product name is required' id='name' name="name" />