<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="AjaxByJquery.WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="jquery-1.8.3.min.js" type="text/javascript"></script> <script type="text/javascript"> // 當把asyn設為false時,這時ajax的請求時同步的,也就是說,這個時候ajax塊發出請求后,他會等待在function1()這個地方,不會去執行function2(),直到function1()部分執行完畢。 // 當把asyn設為true時,這時ajax的請求時異步的,當ajax塊發出請求后,他將停留function1(),等待server端的返回,但同時(在這個等待過程中),前台會去執行function2(), $(document).ready(function () { $.ajax({ type: "POST", url: "value.aspx?act=init", dataType: "html", async:true, success: function (result) { function1() } }); function2(); } ); function function1() { alert('function1'); } function function2() { alert('function2'); } </script> </head> <body> <form id="form1" runat="server"> <div> </div> </form> </body> </html>
參考http://blog.csdn.net/cursor2000/article/details/5677479
代碼下載