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("錯誤");
    }
});


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM