Tôi có một hình thức:Làm cách nào để tải lên dữ liệu tệp + biểu mẫu bằng Tải lên tệp JQuery của blueimp bằng Ajax, không chỉ POST?
<div class="row-fluid">
<div class="span5 row-fluid" id="description" style="margin-left:0px;">
<div>
<label>Title</label>
<input class="span12" type="text" placeholder="Title" id="description_title" name="description_title"/>
<label>Author</label>
<input class="span12" type="text" placeholder="Author" id="description_author" name="description_author"/>
<label>Tags</label>
<input class="span12" type="text" placeholder="Tags" id="description_tags" name="description_tags"/>
<label>Description</label>
<textarea class="span12" id="description_textarea" name="description_textarea" rows="5" style="resize:none"></textarea>
<div id="buttons" class="row-fluid" style="margin-top: 5px">
<div class="span12">
<span class="span5 btn btn-primary btn-file" id="chose_files_btn" onclick="filechose_button.click()">chose files
<input id="filechose_button" type="file" name="fileData" data-url="http://localhost:3001/upload/1234567890"/></span>
<button id="upload_button" type="submit" name="upload" class="span5 offset2 btn btn-success" disabled="true" onclick="$('#upload_form').trigger('upload_fired');">upload</button>
</div> <!-- span12 -->
</div> <!-- buttons -->
</div> <!-- well -->
</div> <!-- video_description -->
</div> <!-- row-fluid -->
Làm thế nào tôi có thể tích hợp một JQuery Tải lên Plugin theo cách như vậy, mà sau khi chọn một tập tin với filechose_button
tôi có thể cho phép các upload_button
và gửi tất cả các trường và tệp đầu vào sử dụng AJAX, không giống như nó hoạt động bây giờ chỉ cần tải lại trang sau khi yêu cầu POST.
js để tải lên là:
$(function() {
$('#filechose_button').fileupload({
dataType: 'json',
add: function (e, data) {
data.context = $('#upload_button');
$('#upload_button').click(function() {
data.submit();
});
},
done: function (e, data) {
data.context.text('Upload finished.');
}
});
});
nhưng vẫn còn đó gửi dữ liệu không sử dụng AJAX
Bạn có thể sử dụng FileUpload nộp cả FileUpload và bổ sung dữ liệu mẫu: https://github.com/blueimp/jQuery-File-Upload/wiki/How-to-submit-additional -form-data – mccannf
:) Tôi đến từ trang đó. Tôi đã viết mã này sau khi đọc hướng dẫn sử dụng đó, nhưng tôi có một vấn đề, rằng biểu mẫu sẽ được gửi đồng bộ, không phải là AJAX. 'Data.submit();' thực hiện không thông qua AJAX – static
Thay vì tạo tệp tin tải lên dựa trên trường nhập, bạn nên bọc các đầu vào của bạn trong một biểu mẫu và tạo tệp tin tải lên với id của biểu mẫu đó. – mccannf