Ajax ?? ??
Ajax ?? ??
jQuery? Ajax ??? ???? ? ?? ?? ??? ?????.
1. jQuery.ajaxSetup( ?? )
?? ? ??
??:
?? AJAX ?? ?? ??? ?????.
??:
??? ???? ?? Ajax ??? ?? ??? ????? ?? ? ??? ???? ??? ??? ? ??? ??? ?? Ajax ??? ?? ??? ?????.
?? ?? ???? ???? ?? ??? ???? Ajax? ?? ??? ?????.
$.ajaxSetup({ url: "../data/AjaxGetMethod.aspx", data: { "param": "ziqiu.zhang" }, global: false, type: "POST", success: function(data, textStatus) { $("#divResult").html(data); }}); 此后我們可以使用無參數(shù)的get(),post()或者ajax()方法發(fā)送 ajax 請求.完整的示例代碼如下: <!doctype html><html><head> <meta charset="utf-8"/> <title>jQuery Ajax - Load</title> <script src="http://code.jquery.com/jquery-3.1.1.min.js"></script> <script> $(document).ready(function() { $.ajaxSetup({ url: "../data/AjaxGetMethod.aspx", data: { "param": "ziqiu.zhang" }, global: false, type: "POST", success: function(data, textStatus) { $("#divResult").html(data); } }); $("#btnAjax").click(function(event) { $.ajax(); }); $("#btnGet").click(function(event) { $.get(); }); $("#btnPost").click(function(event) { $.post(); }); $("#btnGet2").click(function(event) { $.get("../data/AjaxGetMethod.aspx",{ "param": "other" }); }); }); </script></head> <body> <button id="btnAjax">nontransfer param call ajax() method</button><br /> <button id="btnGet">nontransfer param call get() method</button><br /> <button id="btnPost">nontransfer param call post() method</button><br /> <button id="btnGet2">transfer param call get() method , use global default callback</button><br /> <br /> <div id="divResult"></div> </body> </html>
get() ?? post() ???? ??? ? type ????? GET?? ?? ????? ?? ?????. ?? POST, ?? ????? ???? ?? ? ?? ?? ??? ?????. ?? ?? ??? ??? URL? ????? ???? ? ?? ??? ???? ? ??? ??? ??? ???? ???. ?? ??? ?? ???? ?? ??? ??? ???? ??? ???? ?? ?????.
2.serialize( )
??: String
??:
?? ?? ???? ???? Ajax ??? ???? ??????.
???? ?? ???? ??? ?? ? ?? ????? ?????. ???? ???? ?? ???? ?? ?? ???? ??? ? ????.
??? ????? ????? ????? ?? ??? ?? ??? ??? ??? ???.
name ??? ??? ?? ?????. <input id="email" name="email" type="text" />
??:
serialize() ??? ?? ??? ??? ?????. ???? ??? ?????. Ajax? ???? ?? ? ?? ???? ?? ?? ?????. ?? Get ???? ?? ??? ??? ? ?? ??? ??/?? ???? ?? URL? ???? ?? ?????.
3.serializeArray( )
Returns: Array< Object>
??:
JSON ??? ???? ? ??? ????? jQuery? JSON ??? JSON ???? ???? ??? ???? ????. . ??? ?? ??