-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[js] 第68天 formData主要是用来做什么的?它的操作方法有哪些? #492
Labels
js
JavaScript
Comments
1、将form表单元素的name与value进行组合 |
用于后端参数处理为 |
利用 FormData 对象,可以通过 JavaScript 键值对来模拟一系列表单控件,还可以使用 XMLHttpRequest的 |
可以利用formData来上传表单,或者提交上传的文件 document.getElementById('fileBtn').onchange = function () {
//这是传入的内容是空
var fm = new FormData();
//给fm对象添加文件内容
fm.append('icon',this.files[0]);
//发送ajax请求
var xhr = new XMLHttpRequest();
//设置请求行
xhr.open('post','getUrl.php');
//发送数据
xhr.send(fm);
//监听事件完成
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200) {
// console.log(xhr.responseText);
document.querySelector('.imgShow').style.background = "url("+ xhr.responseText +") no-repeat center/cover";
}
}
} |
|
利用 FormData 对象,可以通过 JavaScript 键值对来模拟一系列表单控件,还可以使用 XMLHttpRequest的 send() 方法来异步提交表单。 |
基本上是用于form表单合上传文件。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
第68天 formData主要是用来做什么的?它的操作方法有哪些?
The text was updated successfully, but these errors were encountered: