是否有另一种发送表单数据的方式,我可以使用我使用的脚本,我尝试附加表单数据,但我无法弄清楚如何获取发布数据中的配对值,所以我在URL中添加了数据,这是进度条的问题,然后数据停止在我的页面上工作。
<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);
正如你所看到的,我已经在脚本中对它进行了评论,因为webconsole显示它虽然发送了vidName变量但它没有像这样的识别标签:Content-Disposition:form-data;命名=&#34;视频&#34;
测试ogg创建2
有人可以帮忙吗
答案 0 :(得分:3)
ajax.send("video=" + vidName + "&other=" + other_value);
如果想发送许多值 你可以使用关键字&#34;&amp;&#34;分隔名称和价值
像 视频= vidName, 其它= othervalue1, 其它2 = otherevalue2
将其发送到帖子请求
"video=vidname&other=othervalue1&other2=othervalue2"
在PHP中你可以得到那些帖子数据
$_POST['video'];
$_POST['other'];
$_POST['other2'];
这是一个链接 See it in fiddle