Ajax在jQuery中的應用(載入非同步資料、請求伺服器資料)

來源:互聯網
上載者:User

標籤:應用   llb   warning   style   div   script   load   .com   form   

載入非同步資料
  • jQuery中的load()方法

    load(url,[data],[callback])

    url:被載入的頁面地址  

    [data]:可選項表示發送到伺服器的資料,其格式為 key/value 。   

    [callback]:可選項表示載入成功後,返回至載入頁的回呼函數。

  • 全域函數 getJSON()

    $.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() 方法可以快速注入指令碼,注入的指令碼會自動執行,大大提高了頁面的執行效率。

    getScript() (url,[callback])

  •  非同步載入XML文檔

    $.get(url,[data],callback);

    擷取資料後尋找節點jQuery使用 find("節點名"),如:$(data).find("User").each(function(){})

請求伺服器資料
  • $.get() 請求資料

    $.get(url,[data],callback);

  • $.post() 請求資料

    $.post(url,[data],[callback])

  • serialize() 序列化表單

    $("#form").serialize()

  

Ajax在jQuery中的應用(載入非同步資料、請求伺服器資料)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.