ajax 的三种使用方法

第一种 也是最古老的一种方法之一

from 表单直接提交数据到php文件里

action为路径

        <form method="post" action="./index.php">
            <input name="username" placeholder="用户名"  type="text"  >
            <input name="password"placeholder="密码" type="password">
            <input value="登录" type="submit">
        </form>

data为要传递的参数  

$.post(路径,{"data":data},function(a){
    alert(a);
},"json");

jq提交方式

$.ajax({
   url:"./index.php",
   type:"post",
   data:{username:username},
   dataType:"json",
   success:function(a){
      alert(a)
   },
   error:function(e){
      alert("错误");
    }
});
原文地址:https://www.cnblogs.com/junyi-bk/p/10783202.html