Django中怎么利用ajax异步刷新获取数据

发布时间:2021-07-29 14:38:41 作者:Leah
来源:亿速云 阅读:411

今天就跟大家聊聊有关Django中怎么利用ajax异步刷新获取数据,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

  1. <script>


  2.     function  mysqlping() {

  3.         var $host = $("#dbname").val();

  4.         var $port = $("#dport").val();

  5.         var $eserver = $("#eserver").val();

  6.           $.ajax({

  7.                 type:'post',

  8.                 url:'/eproject/edatabase/add/',

  9.                 data:{a:$host,b:$port,c:$eserver},

  10.                 dataType:"json",

  11.                 success:function(msg){

  12.                     if (msg.status)

  13.                     {

  14.                        swal({

  15.                             icon: "success",

  16.                             text: "SSH连接成功!",

  17.                             });

  18.                     }

  19.                     else

  20.                     {

  21.                         swal({

  22.                             icon: "error",

  23.                             text: "SSH连接失败!",

  24.                             });

  25.                     }

  26.                     }




  27.           });


  28.     }

  29.     </script>

views层获取数据的方法

  1. if request.is_ajax():

  2.         dbname=request.POST.get('a')

  3.         dport=request.POST.get('b')

  4.         print '8888888888888',dbname,dport





GET方式异步刷新传数据的方法(常用于 list展示页面)

  1. function cheshi{{ release.id }}()

  2.      {

  3.      $.getJSON('/serman/release/list/',{'a':{{ release.id }},'b':{{ release.status }} },function(ret){

  4.                                                       // 填入数据

  5.                                                     if (ret.status == '0'){

  6.                                                          swal({

  7.                                                           icon: "error",

  8.                                                           text: "发布中,请不要重复发布!",

  9.                                                         });

  10.                                                     else {

  11.                                                         swal({

  12.                                                           icon: "error",

  13.                                                           text: "未知错误!",

  14.                                                         });


  15.                                                          window.open('{% url 'release_list' %}', "_self");


  16.                                                     }



  17.                                                 })


  18.                                             }


views层获取数据的方法

  1. if request.is_ajax():

  2.         ret = {}

  3.         delid=request.GET.get('a','')

看完上述内容,你们对Django中怎么利用ajax异步刷新获取数据有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

推荐阅读:
  1. python中django原生sql如何获取数据
  2. django中怎么利用ajax实现邮箱用户注册

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

django ajax

上一篇:XamarinEssentials中怎么获取首选项的值

下一篇:python中怎么利用cx_Oracle连接oracle数据库

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》