【Django】ajax 非同步重新整理獲取資料

小亮520cl發表於2018-01-15
個人筆記~~~~~~~~~~~~~~~
POST方式非同步重新整理傳資料的方法(常用於 編輯 新增頁面)

  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','')



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-2150167/,如需轉載,請註明出處,否則將追究法律責任。

相關文章