AJAX 利用JQuery實現AJAX請求
阿新 • • 發佈:2018-12-30
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JqueryAjax.aspx.cs" Inherits="XXX.WebApp.JqueryAjax" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script src="../Js/jquery-1.7.1.js"></script> <script type="text/javascript"> $(function() { //get請求 $("#btnGet").click(function(){ $.get("GetDate.ashx", { "name": "lisi", "pwd": "123" }, function (data) { //get請求,function是回撥函式,data是從伺服器返回的資料 alert(data) }); }); //post請求 $("#btnPost").click(function () { $.post("ShowDate.aspx", { "name": "lisi", "pwd": "123" }, function (data) { //post請求 alert(data) }) }); }); </script> </head> <body> <form id="form1" runat="server"> <div> <input type="button" value="GET獲取資料" id="btnGet" /> <input type="button" value="POST獲取資料" id="btnPost" /> </div> </form> </body> </html>