0

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

1 回答 1

0

inputs 必须有names 才能提交。

例如:

<input type='text' required title='Product name is required' id='name' name="name" />
于 2013-02-08T15:33:28.763 回答