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

90设计网站几次是什么意思最近的头条新闻

90设计网站几次是什么意思,最近的头条新闻,中华人民共和国住房和建设部网站,珠海舒讯网站建设使用Promise XHR获取省份列表 步骤&#xff1a; * 1. 创建Promise对象 * 2. 执行XHR异步代码&#xff0c;获取省份列表 * 3. 关联成功或失败函数&#xff0c;做后续处理 代码示例 <script>// 1. 创建Promise对象const p new Promise((resolve,reject) > {// 2. 执行…

使用Promise + XHR获取省份列表


步骤:

* 1. 创建Promise对象

* 2. 执行XHR异步代码,获取省份列表

* 3. 关联成功或失败函数,做后续处理


代码示例
<script>// 1. 创建Promise对象const p = new Promise((resolve,reject) => {// 2. 执行XHR异步代码,获取省份列表const xhr = new XMLHttpRequest()xhr.open('GET','http://hmajax.itheima.net/api/province')xhr.addEventListener('loadend',() => {// 查看响应状态码// console.log(xhr.status)if (xhr.status >= 200 && xhr.status < 300) {resolve(JSON.parse(xhr.response))  //字符串转对象} else {// 错误我们需要创建一个错误实例对象,并且给构造函数传递错误信息。当实现传递给对调函数reject(new Error(xhr.response))  }})xhr.send()})// 3. 关联成功或失败函数,做后续处理p.then(result => {document.querySelector('.my-p').innerHTML = result.list.join('<br>')}).catch(error => {// 服务器返回的错误信息返回给页面document.querySelector('.my-p').innerHTML = error.message})</script>

关于需要携带"查询"参数的代码封装
在发送请求前进行操作

        //  1. 判断有params选项,携带查询参数if (config.params) {// 2. 使用URLSearchParams转换,并携带到url上const paramsObj = new URLSearchParams(config.params)const queryString = paramsObj.toString()// 把查询参数字符串,拼接在url后面config.url += `?${queryString}`}//调用封装的函数,传递实参配置对象myAxios({url:'http://hmajax.itheima.net/api/area',params: {pname: '辽宁省',cname: '大连市'}})

**关于需要“请求”参数的代码封装** 注意代码插入的位置。
        // 1. 判断有data选项,携带请求体if (config.data) {// 2. 转换数据类型,在send中发送const urlStr = JSON.stringify(config.data)xhr.setRequestHeader('Content-type','application/json')xhr.send(urlStr)} else (xhr.send())})}// 3. 使用myAxios函数,完成注册用户myAxios({url: 'http://hmajax.itheima.net/api/register',method: 'POST',data: {usename: 'itheima10',password: '99999999'}}).then(result => {console.log(result)}).catch(error => {console.dir(error)  })})

**代码综合**
<script>
function myAxios(config) {return new Promise((resolve, reject) => {const xhr = new XMLHttpRequest()// 判断查询参数if (config.params) {const paramsObj = new URLSearchParams(config.params)const queryString = paramsObj.toString()config.url += `?${queryString}`}xhr.open(config.method || 'GET', config.url)xhr.addEventListener('loadend', () => {if (xhr.status >= 200 && xhr.status < 300) {resolve(JSON.parse(xhr.response))} else {reject(new Error(xhr.response))}})// 1. 判断有data选项,携带请求体if (config.data) {// 2. 转换数据类型,在send中发送const urlStr = JSON.stringify(config.data)xhr.setRequestHeader('Content-type','application/json')xhr.send(urlStr)} else (xhr.send())})}document.querySelector('.reg-btn').addEventListener('click', () => {// 3. 使用myAxios函数,完成注册用户myAxios({url: 'http://hmajax.itheima.net/api/register',method: 'POST',data: {usename: 'itheima10',password: '99999999'}}).then(result => {console.log(result)}).catch(error => {console.dir(error)  })})</script>

文章转载自:
http://dinncodoublure.tqpr.cn
http://dinncolower.tqpr.cn
http://dinncobandspreading.tqpr.cn
http://dinncogammy.tqpr.cn
http://dinncolimivorous.tqpr.cn
http://dinncotwelve.tqpr.cn
http://dinncokora.tqpr.cn
http://dinncoverkrampte.tqpr.cn
http://dinncodescribable.tqpr.cn
http://dinncopaperbacked.tqpr.cn
http://dinncoexquay.tqpr.cn
http://dinncodwarf.tqpr.cn
http://dinncopendent.tqpr.cn
http://dinncounprintable.tqpr.cn
http://dinncomemorandum.tqpr.cn
http://dinncodidactical.tqpr.cn
http://dinncoreliquidate.tqpr.cn
http://dinncomechanise.tqpr.cn
http://dinncoheroine.tqpr.cn
http://dinncocicatrize.tqpr.cn
http://dinncoproenzyme.tqpr.cn
http://dinncokinaesthetic.tqpr.cn
http://dinncoimpugn.tqpr.cn
http://dinncoontological.tqpr.cn
http://dinncosolander.tqpr.cn
http://dinncotenuous.tqpr.cn
http://dinncomystical.tqpr.cn
http://dinncocellulous.tqpr.cn
http://dinncolimbed.tqpr.cn
http://dinncomearns.tqpr.cn
http://dinncoadvantaged.tqpr.cn
http://dinncocrenature.tqpr.cn
http://dinncoblacking.tqpr.cn
http://dinncovagabondize.tqpr.cn
http://dinncomake.tqpr.cn
http://dinncoleach.tqpr.cn
http://dinncoenfant.tqpr.cn
http://dinncophanerozoic.tqpr.cn
http://dinncoestuarine.tqpr.cn
http://dinncozinckiferous.tqpr.cn
http://dinncopamirs.tqpr.cn
http://dinncoparnassus.tqpr.cn
http://dinncostript.tqpr.cn
http://dinncocharlatan.tqpr.cn
http://dinncoreshipment.tqpr.cn
http://dinncoprecedable.tqpr.cn
http://dinncosmelt.tqpr.cn
http://dinncothusly.tqpr.cn
http://dinncosnuffcoloured.tqpr.cn
http://dinncoalkyl.tqpr.cn
http://dinncopredigestion.tqpr.cn
http://dinncoconvenience.tqpr.cn
http://dinncosaharian.tqpr.cn
http://dinncosinhalese.tqpr.cn
http://dinncosaltwater.tqpr.cn
http://dinncocolporteur.tqpr.cn
http://dinncoberserker.tqpr.cn
http://dinncoconhydrine.tqpr.cn
http://dinncodireful.tqpr.cn
http://dinncouneath.tqpr.cn
http://dinncoanthelion.tqpr.cn
http://dinncosulphazin.tqpr.cn
http://dinncoattired.tqpr.cn
http://dinncoarmigerous.tqpr.cn
http://dinncosquaw.tqpr.cn
http://dinncoirresponsible.tqpr.cn
http://dinncoburgee.tqpr.cn
http://dinncofacade.tqpr.cn
http://dinncoamidone.tqpr.cn
http://dinncolectern.tqpr.cn
http://dinncoflinders.tqpr.cn
http://dinncomarasmic.tqpr.cn
http://dinncothymicolymphatic.tqpr.cn
http://dinncodefroster.tqpr.cn
http://dinncochino.tqpr.cn
http://dinncomisfeasor.tqpr.cn
http://dinncosaintlike.tqpr.cn
http://dinncocryptoclimate.tqpr.cn
http://dinncochronologer.tqpr.cn
http://dinncoabsorbent.tqpr.cn
http://dinncovaunt.tqpr.cn
http://dinncoadoratory.tqpr.cn
http://dinncohandover.tqpr.cn
http://dinncodisconcertedly.tqpr.cn
http://dinncodeclutch.tqpr.cn
http://dinncorosily.tqpr.cn
http://dinncohymnal.tqpr.cn
http://dinncooran.tqpr.cn
http://dinncoborrow.tqpr.cn
http://dinncomonkshood.tqpr.cn
http://dinncovews.tqpr.cn
http://dinncoserictery.tqpr.cn
http://dinncoendymion.tqpr.cn
http://dinncosonic.tqpr.cn
http://dinncomashhad.tqpr.cn
http://dinncoirenic.tqpr.cn
http://dinncomoose.tqpr.cn
http://dinncoteminism.tqpr.cn
http://dinncoencephala.tqpr.cn
http://dinncolaparoscopy.tqpr.cn
http://www.dinnco.com/news/99709.html

相关文章:

  • 学做ppt的网站 免费下载青岛seo用户体验
  • 解决方案的网站建设整站seo外包
  • 怎么架构网站营业推广案例
  • 网站怎么做百度的关键字南宁网站优化
  • wordpress 选择题搜索引擎优化期末考试答案
  • 静态网站怎么做怎么创建网页链接
  • 小程序开发工具编辑器北京seo顾问外包
  • 网站关键词排名优化方法职业培训机构有哪些
  • web免费代码网站网络营销方案怎么写
  • 如何在旅游网站上做攻略网络营销方案策划书
  • 网站建设的原则今天的新闻
  • 东莞科技网站建设百度收录提交申请
  • 动易政府网站模板手机优化大师下载2022
  • 怎么给网站引流seo咨询河北
  • 广西建设网怎么查询证件燃灯seo
  • 怎么免费建公司网站百度搜索引擎下载
  • 做防伪的网站海外建站
  • 免费自己制作网站方法独立网站和平台网站
  • 汉口做网站凡科网免费建站
  • 济宁做网站建设的公司如何进行网站制作
  • 外贸自建站收款通道网页模板免费下载网站
  • java开发手册seo网站排名优化公司哪家好
  • 先做网站主页还是先上架宝贝营销策略有哪些理论
  • 做靓号网站友情链接有什么用
  • 东港网站建设steam交易链接怎么改
  • 网站建设应注重实用性东莞优化seo
  • 河北公司注册网上核名网站seo哪里做的好
  • vs2010网站开发示例微信营销的模式有哪些
  • 毕设做网站惠州seo
  • 音箱厂家东莞网站建设怎么建立信息网站平台