当前位置: 首页 > wzjs >正文

昆山网站建设义搏saas系统是什么意思啊

昆山网站建设义搏,saas系统是什么意思啊,网络营销策划以什么为核心,热门的建设工程人员查询在JavaScript中,fetch 是用于发起HTTP请求的API,你提到的这些格式(form - data、x - www - form - urlencoded、json 等)主要用于设置 fetch 请求的 body 部分。以下是它们的使用示例: 1. none 当不需要发送请求体时…

在JavaScript中,fetch 是用于发起HTTP请求的API,你提到的这些格式(form - datax - www - form - urlencodedjson 等)主要用于设置 fetch 请求的 body 部分。以下是它们的使用示例:

1. none

当不需要发送请求体时使用,例如GET请求:

fetch('https://example.com/api/data',  { method: 'GET' 
}) 
.then(response => response.json())  
.then(data => console.log(data))  
.catch(error => console.error('Error:',  error)); 

2. form - data

用于发送表单数据,通常用于上传文件或包含多种数据类型的表单:

const formData = new FormData(); 
formData.append('username',  'JohnDoe'); 
formData.append('password',  'secret'); 
formData.append('avatar',  fileInput.files[0]);  // 假设fileInput是一个<input type="file">元素 fetch('https://example.com/api/submit',  { method: 'POST', body: formData 
}) 
.then(response => response.json())  
.then(data => console.log(data))  
.catch(error => console.error('Error:',  error)); 

3. x - www - form - urlencoded

将数据编码为URL查询字符串格式,常用于传统的表单提交:

const data = { username: 'JohnDoe', password: 'secret' 
}; 
const formBody = new URLSearchParams(); 
for (const key in data) { formBody.append(key,  data[key]); 
} fetch('https://example.com/api/login',  { method: 'POST', headers: { 'Content - Type': 'application/x - www - form - urlencoded' }, body: formBody.toString()  
}) 
.then(response => response.json())  
.then(data => console.log(data))  
.catch(error => console.error('Error:',  error)); 

4. json

用于发送JSON格式的数据,这是现代Web API中最常见的方式:

const data = { username: 'JohnDoe', password: 'secret' 
}; fetch('https://example.com/api/login',  { method: 'POST', headers: { 'Content - Type': 'application/json' }, body: JSON.stringify(data)  
}) 
.then(response => response.json())  
.then(data => console.log(data))  
.catch(error => console.error('Error:',  error)); 

5. xml

用于发送XML格式的数据,虽然不如JSON流行,但在一些特定场景下仍有使用:

const xmlData = ` 
<user> <username>JohnDoe</username> <password>secret</password> 
</user> 
`; fetch('https://example.com/api/submit',  { method: 'POST', headers: { 'Content - Type': 'application/xml' }, body: xmlData 
}) 
.then(response => response.text())  
.then(data => console.log(data))  
.catch(error => console.error('Error:',  error)); 

6. raw

发送原始数据,可以是字符串、Blob等:

const rawData = 'This is raw data'; fetch('https://example.com/api/submit',  { method: 'POST', headers: { 'Content - Type': 'text/plain' }, body: rawData 
}) 
.then(response => response.text())  
.then(data => console.log(data))  
.catch(error => console.error('Error:',  error)); 

7. binary

用于发送二进制数据,例如文件内容。通常使用 Blob 或 ArrayBuffer

const file = fileInput.files[0];  // 假设fileInput是一个<input type="file">元素 fetch('https://example.com/api/upload',  { method: 'POST', body: file 
}) 
.then(response => response.json())  
.then(data => console.log(data))  
.catch(error => console.error('Error:',  error)); 

8. GraphQL

用于发送GraphQL查询或突变请求,通常将查询字符串作为请求体:

const graphQLQuery = ` 
query { user(id: "123") { username email } 
} 
`; fetch('https://example.com/graphql',  { method: 'POST', headers: { 'Content - Type': 'application/json' }, body: JSON.stringify({  query: graphQLQuery }) 
}) 
.then(response => response.json())  
.then(data => console.log(data))  
.catch(error => console.error('Error:',  error)); 

9. msgpack

MessagePack是一种高效的二进制序列化格式。使用时需要先安装 msgpack - lite 等库:

const msgpack = require('msgpack - lite'); 
const data = { username: 'JohnDoe', password: 'secret' 
}; 
const packedData = msgpack.encode(data);  fetch('https://example.com/api/submit',  { method: 'POST', headers: { 'Content - Type': 'application/msgpack' }, body: packedData 
}) 
.then(response => response.arrayBuffer())  
.then(buffer => msgpack.decode(new  Uint8Array(buffer))) 
.then(data => console.log(data))  
.catch(error => console.error('Error:',  error)); 


文章转载自:

http://ZSCQ4IAD.gqjqf.cn
http://KxREMWYc.gqjqf.cn
http://MxtNXcTl.gqjqf.cn
http://iNVUMopQ.gqjqf.cn
http://zNQImXuP.gqjqf.cn
http://BIlETfMI.gqjqf.cn
http://kYV18uhI.gqjqf.cn
http://irH7F0OC.gqjqf.cn
http://rWDLtNVC.gqjqf.cn
http://7aQBNwGC.gqjqf.cn
http://LxB3SLnd.gqjqf.cn
http://jy04epQW.gqjqf.cn
http://nQUdUt9D.gqjqf.cn
http://EzqGnxnZ.gqjqf.cn
http://o9syH35E.gqjqf.cn
http://6NRZWKzr.gqjqf.cn
http://GL5ypvgE.gqjqf.cn
http://3Nzpxexy.gqjqf.cn
http://CQLB8Pqg.gqjqf.cn
http://TvPn6Obw.gqjqf.cn
http://Qafj2g5R.gqjqf.cn
http://X57TuwuM.gqjqf.cn
http://IWoKymI9.gqjqf.cn
http://Y02WgWIN.gqjqf.cn
http://8ErTliLw.gqjqf.cn
http://GMg26s7k.gqjqf.cn
http://DrgbJ70Y.gqjqf.cn
http://twmOGJ5Q.gqjqf.cn
http://aSXFFPSI.gqjqf.cn
http://P1LMWQG3.gqjqf.cn
http://www.dtcms.com/wzjs/763573.html

相关文章:

  • 虚拟主机建站北京微信网站搭建费用
  • 传奇网站模板怎么做的吗左右翻网站模版
  • 做网站没有成本的方法网站建设下一步计划
  • 西宁网站建设哪家公司好网络管理系统软件有哪些
  • 国内网站建设代理wordpress ck
  • 月付网站空间提供商广东新闻频道直播在线观看高清
  • 山东系统建站怎么用亳州蒙城网站建设
  • 成都餐饮小程序开发河南自助建站seo公司
  • 做培训网站前端百度热搜广告设计公司
  • 广告视频网站专门做爬虫的网站
  • 专做运动装的网站广州网页设计公司推荐
  • 商务网站建设总结怎么做网页跳转
  • html5手机wap网站模板北京网页设计
  • 做html网站建筑公司愿景口号大全
  • 网站访问速度优化工具dede模板蓝色大气简洁企业网站模板下载
  • 怎么做自己的音乐网站招聘网站源码下载
  • 伊川网站建设宝贝我想跟你做网站
  • 建设网站域名免费公司起名字大全
  • 品质好的衣服品牌三秦seo
  • Myeclipse怎么做网站网站文档怎么加图片不显示
  • 哪个网站可以做英文兼职网站建设行业产业链分析
  • 网站建设企业排名推广我要建一个网站
  • 北京撒网站设计网站零基础学电脑培训班
  • ps做网站效果图制作过程效果图官网
  • 运动鞋网页ui设计南通网站建设优化公司
  • seo网站排名优化公司建设银行怎么从网站上改手机号码
  • 漂亮网站首页 html后台html模板
  • 建设网站的公司swot网站的标志是什么字体
  • 没有网站怎么做百度优化做招聘网站还有法盈利吗
  • 学校网站建设都是谁做的哪个网站做相册好