Flask与ajax(jQuery)交互的几种方法:$.post、$.get、$.getJSON 、$.ajax、 $.load

该博客详细介绍了如何使用jQuery的$.post、$.get、$.getJSON、$.ajax和$.load方法与Flask后端进行数据交互。通过示例代码展示了前端index.html与Flask的run.py配合,实现不同AJAX请求的使用场景。提供了一个完整的代码示例库链接供下载参考。
摘要由CSDN通过智能技术生成

本文介绍jQuery封装的几种ajax方法与Flask后端交互的实现。jQuery封装的ajax方法有post、get、getJSON、ajax、load等,使用起来很方便。


目录结构如下:

|--|
   |--run.py
   |--static
      |--test.txt
   |--templates
      |--index.html


前端代码如下:

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Jquery Ajax Test</title>
    <script src="https://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
    </script>
<script>
$(document).ready(function(){
   $(".btn1").click(function(){
      $.get("/mystring",function(data, status){
         alert("数据: " + data + "\n状态: " + status);
      });
   });

    $(".btn2").click(function(){
      $.get("/mydict",function(data, status){
         alert("name: " + data.name + " age:" + data.age);
      });
   });

    $(".btn3").click(function(){
      <
  • 0
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值