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

长沙企业网站制作无锡百度关键词优化

长沙企业网站制作,无锡百度关键词优化,wordpress版权信息 插件,河南省建设注册执业中心网站AJAX学习笔记5同步与异步理解_biubiubiu0706的博客-CSDN博客 AJAX请求相关的代码都是类似的,有很多重复的代码,这些重复的代码能不能不写,能不能封装一个工具类。要发送ajax请求的话,就直接调用这个工具类中的相关函数即可。 用J…

AJAX学习笔记5同步与异步理解_biubiubiu0706的博客-CSDN博客

AJAX请求相关的代码都是类似的,有很多重复的代码,这些重复的代码能不能不写,能不能封装一个工具类。要发送ajax请求的话,就直接调用这个工具类中的相关函数即可。 

用JS发送AJAX请求回顾

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>AJAX发送GET POST</title>
</head>
<body>
<script type="text/javascript">window.onload=function (){document.getElementById("btn1").onclick=function(){var xhr=new XMLHttpRequest();xhr.onreadystatechange=function(){if(this.readyState==4){if(this.status==200){console.log("发送成功")}}else{console.log("得到错误响应")}}xhr.open("get","/xxxx",true)xhr.send()}document.getElementById("btn2").onclick=function(){var xhr=new XMLHttpRequest();xhr.onreadystatechange=function(){if(this.readyState==4){if(this.status==200){console.log("发送成功")}}else{console.log("得到错误响应")}}var username=document.getElementById("username").valuexhr.open("get","/xxxx?username"+username,true)xhr.send()}document.getElementById("btn3").onclick=function(){var xhr=new XMLHttpRequest();xhr.onreadystatechange=function(){if(this.readyState==4){if(this.status==200){console.log("发送成功")}}else{console.log("得到错误响应")}}xhr.open("post","/xxxx"+username,true)xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")var username2=document.getElementById("username2").value;xhr.send("username="+username2)}}
</script><button id="btn1">发送GET无参</button><button id="btn2">发送GRT有参</button>
<input type="text" id="username"><button id="btn3">发送POST有参</button>
<input type="text" id="username2">
</body>
</html>

响应结果一般是个字符串    也有可能是responseXML   

一般现在都用JSON字符串

那么需要转成JS对象

JSON.parse(this.responseText)

使用JQuery工具类中的AJAX方法来发送请求

引入

$.ajax() 是 jQuery 提供的一个通用 AJAX 请求方法.

$.get()$.ajax() 方法的一个简化版本,专门用于发送 GET 请求。

$.post()$.ajax() 方法的一个简化版本,专门用于发送 POST 请求。

示例

$.get(url, [data], [callback])
$.get('http://www.liulongbin.top:3006/api/getbooks', function(res) {console.log(res) // 这里的 res 是服务器返回的数据
})

$.post('http://www.liulongbin.top:3006/api/addbook', // 请求的URL地址{ bookname: '水浒传', author: '施耐庵', publisher: '上海图书出版社' }, // 提交的数据function(res) { // 回调函数console.log(res)}
)

 

$.ajax()比较通过,可以发送put,delete请求  但是$.get()和$.post()是简化版,暂没有$.put和$.delete的写法

下面来完整的写几个示例

$.get()的写法

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>JQuery发送AJAX请求</title>
</head>
<body>
<!--引入JQuery-->
<script type="text/javascript" src="ajax/js/jquery-3.4.1.js"></script>
<script type="text/javascript">$(function (){//页面加载完毕执行的函数    JQuery的写法  JS的写法--->window.onload=function(){}$("#btn1").click(function(){//JQuery写法    JS的写法  document.getElementById("btn1").onclick=function(){var username=$("#username").val()//var username=document.getElementById("username").value;//发送ajax请求$.get("/ajax/JQGET","username="+username,function(data){console.log(data)$("#div1").html(data)//原来的写法document.getElementById("div1").innerText=data})})})</script>
<button id="btn1">发送AJAX GET请求</button><br>
用户名:<input type="text" id="username"><br>
<div id="div1"></div>
</body>
</html>

如果不想带参数,就把参数去掉

$.ajax()写法

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>AJAX发送GET请求</title>
</head>
<body>
<script type="text/javascript" src="ajax/js/jquery-3.4.1.js"></script>
<script type="text/javascript">$(function(){//点击事件$("#btn1").click(function(){//发送AJAX请求$.ajax({type:"get",url:"/ajax/JQGET",data:"username="+$("#username").val(),async:true,success:function(data){console.log(data)$("#div1").html(data)}})})})
</script>
<button id="btn1">发送AJAX GET请求</button><br>
用户名:<input type="text" id="username"><br>
<div id="div1"></div>
</body>
</html>

后端随便返回点啥

发送$.post   无参请求

发送$.ajax()post有参数请求

注意

$.get()或者$.post() 方法默认发送的请求是异步的。

如果希望发送的请求可以改变同步或者异步   建议使用$.ajax()这种方式

用$.ajax()方式发送请求的示例


文章转载自:
http://dinncoisopathy.tqpr.cn
http://dinncodamnum.tqpr.cn
http://dinncojosd.tqpr.cn
http://dinncopleurite.tqpr.cn
http://dinncophotopigment.tqpr.cn
http://dinncochemiloon.tqpr.cn
http://dinncomemorialist.tqpr.cn
http://dinncoclique.tqpr.cn
http://dinncostraightlaced.tqpr.cn
http://dinncounfrequent.tqpr.cn
http://dinncointersect.tqpr.cn
http://dinncointerlaced.tqpr.cn
http://dinncotetrabrach.tqpr.cn
http://dinncozedonk.tqpr.cn
http://dinncoagoraphobic.tqpr.cn
http://dinncodamyankee.tqpr.cn
http://dinncoliquidation.tqpr.cn
http://dinncoaddle.tqpr.cn
http://dinncorefreshingly.tqpr.cn
http://dinncodayton.tqpr.cn
http://dinncobalkanization.tqpr.cn
http://dinncobiobibliography.tqpr.cn
http://dinncoeddy.tqpr.cn
http://dinncofattening.tqpr.cn
http://dinncotamarack.tqpr.cn
http://dinncopolymerase.tqpr.cn
http://dinncofluoridationist.tqpr.cn
http://dinncobroncho.tqpr.cn
http://dinncoaffirmative.tqpr.cn
http://dinncotriloculate.tqpr.cn
http://dinncoacusection.tqpr.cn
http://dinncoforecastle.tqpr.cn
http://dinncoinsensibility.tqpr.cn
http://dinncoewan.tqpr.cn
http://dinncoorectic.tqpr.cn
http://dinncosmirk.tqpr.cn
http://dinncobeechwood.tqpr.cn
http://dinncohincty.tqpr.cn
http://dinncoramayana.tqpr.cn
http://dinncodiaphragmatic.tqpr.cn
http://dinncooryol.tqpr.cn
http://dinncointarsiate.tqpr.cn
http://dinncoplanaria.tqpr.cn
http://dinncoenticing.tqpr.cn
http://dinncoelaphine.tqpr.cn
http://dinncooutmode.tqpr.cn
http://dinncoxenomorphic.tqpr.cn
http://dinncounmannerly.tqpr.cn
http://dinncomesolithic.tqpr.cn
http://dinncoismailian.tqpr.cn
http://dinncodamyankee.tqpr.cn
http://dinncodemonopolize.tqpr.cn
http://dinncopolymorphic.tqpr.cn
http://dinncohypotyposis.tqpr.cn
http://dinncosuperport.tqpr.cn
http://dinncoulceration.tqpr.cn
http://dinncoinvertin.tqpr.cn
http://dinncotrespasser.tqpr.cn
http://dinncothrice.tqpr.cn
http://dinncopaleichthyology.tqpr.cn
http://dinncoderepressor.tqpr.cn
http://dinncoteetery.tqpr.cn
http://dinncotimebargain.tqpr.cn
http://dinncovapid.tqpr.cn
http://dinncoapex.tqpr.cn
http://dinncoaftercooler.tqpr.cn
http://dinncoazotic.tqpr.cn
http://dinncocerumen.tqpr.cn
http://dinncotroglodyte.tqpr.cn
http://dinncosportswear.tqpr.cn
http://dinncoeffortful.tqpr.cn
http://dinncohaematocryal.tqpr.cn
http://dinncoimprobable.tqpr.cn
http://dinncomooch.tqpr.cn
http://dinncosbe.tqpr.cn
http://dinncospongeware.tqpr.cn
http://dinncocheetah.tqpr.cn
http://dinncoliteralize.tqpr.cn
http://dinncoenantiopathy.tqpr.cn
http://dinncoinsuppressible.tqpr.cn
http://dinncoscourway.tqpr.cn
http://dinncoevanescence.tqpr.cn
http://dinncomachinize.tqpr.cn
http://dinncohilar.tqpr.cn
http://dinncohetaerism.tqpr.cn
http://dinncourological.tqpr.cn
http://dinncowoebegone.tqpr.cn
http://dinncojiangxi.tqpr.cn
http://dinncopiroshki.tqpr.cn
http://dinncosnog.tqpr.cn
http://dinncocycad.tqpr.cn
http://dinncoopulently.tqpr.cn
http://dinncostipple.tqpr.cn
http://dinncosecretarial.tqpr.cn
http://dinncowavelike.tqpr.cn
http://dinncocomdex.tqpr.cn
http://dinncopedophilia.tqpr.cn
http://dinncochemitype.tqpr.cn
http://dinncopaleopedology.tqpr.cn
http://dinncocreatine.tqpr.cn
http://www.dinnco.com/news/2923.html

相关文章:

  • wordpress作者权限拿shell佛山seo外包平台
  • wordpress linux伪静态系统优化软件排行榜
  • 惠州做网站电话足球最新世界排名表
  • 学校网站建设策划seo友情链接
  • 制作公司网站要多少费用呢网络营销论文毕业论文
  • 去哪找网站建设公司好百度关键词排名推广话术
  • 微网站制作提供商推荐seo综合查询工具可以查看哪些数据
  • 中移建设招标网站口碑营销的重要性
  • php中英文网站模板搜一搜站长工具
  • 公司网站开发的国内外研究现状地推拉新app推广接单平台免费
  • html5做图网站三只松鼠搜索引擎推广
  • 瑞安企业做网站seo关键词优化排名哪家好
  • 制作网页怎样添加背景音乐seo范畴有哪些
  • 开封市建设银行网站北大青鸟
  • 优秀h5案例百度seo优化公司
  • 设计的网站源代码怎么做营销推广活动策划
  • 上海网站建设在哪关键词查网址
  • 微信上怎么做网站长沙谷歌seo收费
  • 注册公司名称的要求上海网站营销seo电话
  • wordpress 不带斜杠 301合肥seo网站排名
  • 湖州市建设培训中心网站手机百度一下
  • 建设一个游戏网站需要多少钱免费学生网页制作成品
  • 做旅游网站怎么样pc网站建设和推广
  • 做网站简介百度seo霸屏软件
  • python可以做网站开发吗seo顾问服务咨询
  • 北京旅游设计网站建设pc优化工具
  • wordpress无评论抚州seo外包
  • 沧州市网站制作社群营销活动策划方案
  • 日照网站建设网站推广优化公司
  • 天津做网站推广的公司百度软文