Django - 使用ajax发布多个文件

时间:2017-04-30 14:31:16

标签: javascript jquery ajax django

如何使用ajax在1-6和多个图像文件之间发布数字?我想这样做,因为我想上传文件并显示错误而不刷新,但我无法设置它。甚至可以上传多个图像而不使用任何外部模块等,只需ajax? 表格是模态的。 HTML:

<!-- Modal -->
<div class="modal fade" id="myModalHorizontal" tabindex="-1" role="dialog" 
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <!-- Modal Header -->
            <div class="modal-header">
                <button type="button" class="close" 
                   data-dismiss="modal">
                       <span aria-hidden="true">&times;</span>
                       <span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    Add exam
                </h4>
            </div>

            <!-- Modal Body -->
            <div class="modal-body">


                <form id="form" class="form-horizontal" role="form" method="post" enctype="multipart/form-data" action="{% url 'create_exam' letnik_id=letnik_id classes_id=classes_id subject_id=subject_id %}" id="post-form" onsubmit="myFunction()">
                {% csrf_token %}
                  <div class="form-group" csrf="{{ csrf_token }}">
                    <label  class="col-sm-2 control-label"
                              for="inputEmail3">Številka Testa</label>
                    <div class="col-sm-10">
                        <select class="form-control" id="exam_number" name="exam_number">
                          <option>1</option>
                          <option>2</option>
                          <option>3</option>
                          <option>4</option>
                          <option>5</option>
                          <option>6</option>
                        </select>
                    </div>
                  </div>
                  <div class="form-group">
                    <label class="col-xs-2 control-label"
                           >Pictures</label><br>
                    <div class="col-sm-10">
                        <input  name="exam_file" type="file" accept="*" multiple required>
                    </div>
                  </div>
                  <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                    </div>
                  </div>






            </div>

            <!-- Modal Footer -->
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                            Close
                </button>
                <button  class="btn btn-primary" id="form-submit" type="submit">
                    Add
                </button>
            </div>
            </form>
        </div>
    </div>
</div>

0 个答案:

没有答案