一、$.get和$.post的不同
    1、get通过url提交的,post是通过http消息实体提交的
    2、get提交大小限制为2kb,post不限制
    3、get提交会被缓存下来,有安全隐患,post没有
    4、get通过$.get,而post通过$.post获取

  二、 $.get 和 $.post的几种传参方式
    1、在url后面直接问号传参: test.php?age=20
    2、以字符串键值对的方式传参:  'age=20'
    3、以对象键值对的方式传参:  {age:20}

   $.get 以上三种方式都支持,但是$.post和$.ajax只支持后2种写法
    具体例子:
    1、$.get('URL?age=20',function(result){
        alert(result)
    })
    2、$.get('URL,'age=20',function(result){
        alert(result)
    })
    3、$.get('URL',{age:20},function(result){
        alert(result)
    })

三、$.get 和 $.post方法 成功,完成请求,错误或失败的回调

$.post('URL',$('form').serialize()),success(function(){
            alert(请求成功后);
        }).complete(function({
            alert(请求完成后);
        }).error(function (xhr, status, info) {

   if(xhr.status == 401){

     //do something

   }

})

四、ajax请求 成功,完成请求,错误或失败的回调

$.ajax({
  type:"POST",
  url:"URL",
  data:$('form').serialize(),
  success:function(resp,status){
    if(status == "success"){
      //do something
    }
  },
  error:function(xhr,errorText,errorType){
    if(xhr.status == 401){
      //do something
    }
  },
  complete:function(){
    //do something
  }
})

注:在用ajax 提交表单的时候可以用表单序列化获取表单的传参内容,而且传参的形式是字符串键值对,并且还会对url进行编码,在data设置 $('form').serialize() 即可。

随机推荐

  1. css3 animate转圈360旋转

    .logo{ width:20px; height: 20px; background: red; -webkit-animation:haha1 .8s linear infinite; anima ...

  2. C# lambda 实现 Ascii 排序

    var dir = new Dictionary<string, string>();            dir.Add("channelId", "1& ...

  3. 启动docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

    启动docker提示: docker: Got permission denied while trying to connect to the Docker daemon socket at uni ...

  4. 关于jQ的小案例分享

    <!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>表 ...

  5. python学习笔记(十五)-unittest单元测试的一个框架

    unittest 单元测试的一个框架什么框架 一堆工具的集合. TestCase TestSuite 测试套件,多个用例在一起 TestLoader是用来加载TestCase到TestSuite中的 ...

  6. P2012-拯救世界2【EGF】

    正题 题目链接:https://www.luogu.com.cn/problem/P2012 题目大意 \(12\)种东西排列成长度为\(n\)的序列,要求前四种出现奇数次,后四种出现偶数次,求方案. ...

  7. P4859-已经没有什么好害怕的了【容斥,dp】

    正题 题目链接:https://www.luogu.com.cn/problem/P4859 题目大意 两个长度为\(n\)的序列\(a,b\)两两匹配,求\(a_i>b_i\)的组数比\(a_ ...

  8. 面试官一口气问了MySQL事务、锁和MVCC,我

    面试官:你是怎么理解InnoDB引擎中的事务的? 候选者:在我的理解下,事务可以使「一组操作」要么全部成功,要么全部失败 候选者:事务其目的是为了「保证数据最终的一致性」. 候选者:举个例子,我给你发 ...

  9. typora博客笔记上传图片时不能显示

    前言 markdown具有轻量化.易读易写等特性,并且对于图片.超链接.图片.数学公式都有支持. 但是最近在使用Typora的过程中我发现,在写文章笔记的时候导入的图片,因为图片保存在我们电脑本地,当 ...

  10. openGauss X ShardingSphere,分布式方案的另一种最佳实践

    Apache ShardingSphere 持续助力于 openGauss 分布式数据库能力的构建.openGauss 数据库自 2020 年 6 月开源以来,受到了业界的广泛关注,现已吸引众多伙伴. ...