ajax 的三种使用方法

Posted junyi-bk

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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>

 

js提交方式

data为要传递的参数  

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

 

jq提交方式

$.ajax({
   url:"./index.php",
   type:"post",
   data:{username:username},
   jsonType:"json",
   success:function(a){
      alert(a)
   },
   error:function(e){
      alert("错误");
    }
});

 

以上是关于ajax 的三种使用方法的主要内容,如果未能解决你的问题,请参考以下文章

ajax的三种传参方式

ajax 的三种使用方法

AJAX实现跨域的三种方法

Ajax中data的三种数据类型

Ajax的三种数据传输格式

前端传值给后台的三种方法-韩烨