1
在下面的代碼中,我有一個動態文件上傳,我必須上傳多個文件使用ajax.I嘗試下面的代碼,但請求文件數爲0.請幫我解決這個問題。使用ajax動態文件上傳
<input id="Button1" type="button" class="btn btn-primary" value="Add Files" onclick = "AddFileUpload()" />
function AddFileUpload() {
var div = document.createElement('DIV');
div.innerHTML = '<input id="file' + counter + '" multiple name = "file' + counter +
'" type="file" />' +
'<input id="Button' + counter + '" type="button" ' +
'value="Remove" onclick = "RemoveFileUpload(this)" />' + '<input id="BtnUpld' + counter + '" value="Upload" name = "BtnUpld' + counter +
'" onclick = "Upload()" type="Button" />';
document.getElementById("FileUploadContainer").appendChild(div);
counter++;
}
function Upload() {
$.ajax({
type: "POST",
url: "NewTask.aspx/Upload",
data: '',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
}
});
<div id = "FileUploadContainer">
</div>
[WebMethod]
public static void Upload()
{
if (HttpContext.Current.Request.Files.Count > 0)
{
}
}
你是不是傳遞文件的任何地方?顯示一些'html'以理解你的'DOM'結構..你在調用這個'AddFileUpload'函數..有沒有涉及到任何'form'? –
@Guruprasad Rao看到我更新的問題 – Dotnet