標籤:應用 llb warning style div script load .com form
載入非同步資料
load(url,[data],[callback])
url:被載入的頁面地址
[data]:可選項表示發送到伺服器的資料,其格式為 key/value 。
[callback]:可選項表示載入成功後,返回至載入頁的回呼函數。
$.getJSON(url,[data],[callback])
<div class="container col-lg-12"> <div style="margin:100px 200px;padding:20px; border:1px solid #00ffff"> <form id="form1" action="/" method="post" role="form"> <div class="form-group"> <input type="text" name="name" class="text-primary form-control" placeholder="NAME" /> </div> <div class="form-group"> <input type="password" name="pwd" class="text-primary form-control" placeholder="PASSWORD" /> </div> <div class="form-group"> <input type="text" name="email" class="text-primary form-control" placeholder="EMAIL" /> </div> <div class="form-inline col-lg-offset-4"> <input type="button" class="btn btn-primary" value="Login" style="margin:20px" /> <input type="reset" class="btn btn-warning" value="Reset" /> </div> </form> </div> <div id="tip"></div>
</div>
<script type="text/javascript"> $(function () { $("#form1 :input[type=button]").click(function () { $.getJSON("../../App_Data/UserInfo.json", function (data) { $("#tip").empty(); var strHTML = ""; $.each(data, function (index,Info) { strHTML += "name:" + Info["name"] + "<br>"; strHTML += "sex:" + Info["sex"] + "<br>"; strHTML += "email:" + Info["email"] + "<hr>"; }) $("#tip").html(strHTML); }) }) })</script>
//UserInfo.json 檔案內容[ { "name": "A", "sex": "man", "email": "[email protected]" }, { "name": "B", "sex": "woman", "email": "[email protected]" }]
使用 getScript() 方法可以快速注入指令碼,注入的指令碼會自動執行,大大提高了頁面的執行效率。
getScript() (url,[callback])
$.get(url,[data],callback);
擷取資料後尋找節點jQuery使用 find("節點名"),如:$(data).find("User").each(function(){})
請求伺服器資料
$.get(url,[data],callback);
$.post(url,[data],[callback])
$("#form").serialize()
Ajax在jQuery中的應用(載入非同步資料、請求伺服器資料)