是否有另一種發送表單數據的方式,我可以使用我正在使用的腳本,我嘗試追加表單數據,但我無法弄清楚如何獲得配對值在發佈數據中,所以我在網址中添加了數據,問題是進度條和數據然後停止在我的頁面上工作。如何在ajax中發送額外的表單數據
<script>
function _(el){
return document.getElementById(el);
}
function uploadFile(){
var file = _("video").files[0];
var vidName = $("#vidName").val();
var videoDescription = $("#videoDescription").val();
var albumName1 = $("#choosevidCat").val();
var vidFile =$("#video").val();
var otherData = $('vidUpload').serializeArray()
// alert(file.name+" | "+file.size+" | "+file.type);
var formdata = new FormData();
formdata.append("video", file);
// formdata.append("video", vidName);
var ajax = new XMLHttpRequest();
ajax.upload.addEventListener("progress", progressHandler, false);
ajax.addEventListener("load", completeHandler, false);
ajax.addEventListener("error", errorHandler, false);
ajax.addEventListener("abort", abortHandler, false);
ajax.open("POST", "includes/vid_upload.inc.php?vidName=" +vidName+"&videoDescription=" +videoDescription+"&albumName1="
+albumName1, false);
ajax.send(formdata);
}
function progressHandler(event){
_("loaded_n_total").innerHTML = "Uploaded "+event.loaded+" bytes of "+event.total;
var percent = (event.loaded/event.total) * 100;
_("progressBar").value = Math.round(percent);
_("status").innerHTML = Math.round(percent)+"% uploaded... please wait";
}
function completeHandler(event){
_("status").innerHTML = event.target.responseText;
_("progressBar").value = 0;
}
function errorHandler(event){
_("status").innerHTML = "Upload Failed";
}
function abortHandler(event){
_("status").innerHTML = "Upload Aborted";
}
</script>
我嘗試添加
formdata.append("video", vidName);
,你可以看到我已經在腳本註釋出來作爲Web控制檯顯示,雖然它被髮送vidName變量它沒有有一個這樣的標識標籤:內容 - 配置:表單數據; NAME =「視頻」
測試OGG創建2
任何人都可以幫助請
您能得到什麼,如果你' console.log(FormData.getAll)' –
@Said Kholov林不知道我把它添加在正確的地方,我把它放在結束腳本標記之前,它報告回來是未定義的,並與該位代碼 – Tiny
把它追加後,並嘗試上傳 –