• django基础~jquery交互


    一 绑定事件

      整体结构 $(selector).click(function(){$.ajax({})})

       1 #selector 为选择器标签ID 记得名字要加#    2 $.ajax({method: http方法 url:"url_context",data:JSON.stringify
    {“data”:variables},success:function(arg){},error:function(arg){})
         1 success:function(arg){
             var obj = jQuery.parseJSON(arg); //返回的数据进行join解析
             alert(obj)
            window.location.reload(); //页面刷新
            }}
         2 error:function(arg){
            var obj = jQuery.parseJSON(arg);
           alert(obj)
        }
    二 使用案例
    <script src="/static/js/jquery.js"></script>
    <script src="/static/js/pintuer.js"></script>
    <script src="/static/js/jquery.min.js"></script>
    <script src="/static/js/bootstrap.min.js"></script>
    <script type="text/javascript">
    function test(){
    alert("11111111")
    }
    $("#delete_user").click(function() {
    var id = $(this).parents("tr").children("td:nth-child(1)").text();
    alert("测试")
    $.ajax({
    url: "/api/v1/",
    method: "delete",
    data: JSON.stringify({"username":id}),
    success: function (arg) {
    window.location.reload()
    alert("删除成功")
     
    },
    error: function (arg) {
    var obj = jQuery.parseJSON(arg);
    alert(obj)
    }
    })
    })
    </script>
     

  • 相关阅读:
    git Permissions 0777 for '/home/xxx/.ssh/id_rsa' are too open.
    Linux wc指令解析
    RK3288 开机动画旋转
    tp3.2 事务
    PHP实现动态获取函数参数的方法
    laravel 配置设置
    swoole 使用异步redis的前置条件
    php回调函数的概念及实例
    swoole 安装
    linux 源码安装PHP
  • 原文地址:https://www.cnblogs.com/danhuangpai/p/14578288.html
Copyright © 2020-2023  润新知