Blogger Information
Blog 40
fans 0
comment 1
visits 34275
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JQuery学习之$.get、$.post、$.ajax的应用
景云
Original
458 people have browsed it

引入库

<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>

css

  1. body{
  2. display: grid;
  3. gap: 2em;
  4. padding: 2em;
  5. }

html

  1. <button class="get">GET</button>
  2. <button class="post">POST</button>
  3. <button class="jsonp">JSONP</button>

1. $.get(请求地址,参数,成功回调)

  1. $(".get").click(function(ev){
  2. $.get("users.php",{id:1},function(data){
  3. $(ev.target).after("<span></span>").next().html(data);
  4. })
  5. })

2. $.post

  1. $(".post").click(function(ev){
  2. $.post("users.php",{id:2},function(data){
  3. $(ev.target).after("<div></div>").next().html(data);
  4. })
  5. })

3. $.ajax:jsonp:跨域请求数据

  1. $(".jsonp").click(function(ev){
  2. $.ajax({
  3. type:"get",
  4. url:"http://word.cn/test.php?id=3&jsonp=?",
  5. dataType:"jsonp",
  6. //告诉跨域服务器需要返回的函数名称
  7. jsonpCallback:"show"
  8. })
  9. })
  10. function show(data){
  11. $(".jsonp").after("<div></div>").next().html(data.name);
  12. }
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!