如何将表单门中的文字添加到书名[{1}}中,并将其发送到id:bname
页面,以及如何在upload.php
页面中接收文字。
upload.php
上传文件中的功能
function uploadFile(){
var file = document.getElementById("upload").files[0];
var formdata = new FormData();
formdata.append("upload", file);
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", "upload.php");
ajax.send(formdata);
clikedbtn();
}
html标签
function progressHandler(event){
var percent = (event.loaded / event.total) * 100;
document.getElementById("progressBar").value = Math.round(percent);
}
function completeHandler(event){
document.getElementById("progressBar").value = 0;
}
function errorHandler(event){}
function abortHandler(event){}
function clikedbtn(){}
upload.php的
我想使用我将在此页面中发送的文本
<form method="post" enctype="multipart/form-data">
<label for="bname">book name</label>
<input name="bname" id="sname" type="text">
<label for="dbname">bood desc</label>
<input name="dbname" id="dbname" type="text">
<input id="upload" name="upload" type="file">
<input id="btnupload" type="button" value="add" onclick="uploadFile() ">
</form>
答案 0 :(得分:0)
收到回复:
var ajax = new XMLHttpRequest();// under this line
ajax.onreadystatechange = function() {
if (ajax.readyState === XMLHttpRequest.DONE && ajax.status === 200) {
// you can hanle ajx.responseText
}
};