2012年2月20日 星期一

利用JQuery 結合 Ajax 取值

<script src="js/jquery-1.7.js" type="text/javascript"></script>


<script type="text/javascript"><![CDATA[

 function getAjaxValue() {
               $.ajax({
                type: "POST",
                url: "GetAjaxtValue.aspx/GetAjaxValue",   //(網頁名稱/方法名稱)
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: "{}",
                success: function(data) {
                    $("#<%= txt1.ClientID %>").val(data.d);
                },
                error: function(err) {
                    alert("error");
                }
            });
        }]]></script>
 


<asp:button id="btn1" onclientclick="getAjaxValue(); return false" runat="server" text="透過Ajax取值">
    <asp:textbox height="106px" id="txt1" runat="server">
</asp:textbox></asp:button>



using System.Web.Services;
using System.Web.Script.Services;
[WebMethod]
        public static string GetAjaxValue() {
         return "取得Ajax值";
         }




原始文章出自於此

沒有留言:

張貼留言