zoukankan      html  css  js  c++  java
  • Jqeury ajax 调用C#的后台程序

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="JQueryTest.aspx.cs" Inherits="自定义滚动条_JQueryTest" %>
    
     
    <!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 id="Head1" runat="server">  
        <title></title>  
        <script src="jquery-1.8.3.min.js" type="text/javascript"></script>
        <script type="text/javascript">  
            $(function() {  
                $("#btnOK").click(function() {  
                    $.ajax({  
                        type: "Post",  
                        url: "JQueryTest.aspx/SayHello",  
                        data: "{}",  
                        contentType: "application/json; charset=utf-8",  
                        dataType: "json",  
                        success: function(data) {  
                            alert(data.d);  
                        },  
                        error: function(err) {  
                            alert(err);  
                        }  
                    });  
                    return false;  
                });  
                $("#btnOK0").click(function() {  
                    $.ajax({  
                        type: "Post",  
                        url: "JQueryTest.aspx/GetStr",  
                        data: "{'str':'我是','str2':'XXX'}",  
                        contentType: "application/json; charset=utf-8",  
                        dataType: "json",  
                        success: function(data) {  
                            alert(data.d);  
                        },  
                        error: function(err) {  
                            alert(err);  
                        }  
                    });  
                    return false;  
                });  
                $("#btnOK1").click(function() {  
                    $.ajax({  
                        type: "Post",  
                        url: "JQueryTest.aspx/GetArray",  
                        data: "{}",  
                        contentType: "application/json; chartset=utf-8",  
                        dataType: "json",  
                        success: function(data) {  
                            $("#list").html("");  
                            $(data.d).each(function() {  
                                $("#list").append("<li>" + this + "</li>");  
                            });  
                            alert(data.d);  
                        },  
                        error: function(err) {  
                            alert(err);  
                        }  
                    });  
                    return false;  
                });  
                $("#btnOK2").click(function() {  
                    $.ajax({  
                        type: "Post",  
                        url: "JQueryTest.aspx/GetHash",  
                        data: "{'key':'haha','value':'哈哈!'}",  
                        contentType: "application/json: charset=utf-8",  
                        dataType: "json",  
                        success: function(data) {  
                            alert("key:haha==>" + data.d["haha"] + "/n key:www==>" + data.d["www"]);  
                        },  
                        error: function(err) {  
                            alert(err + "err");  
                        }  
                    });  
                    return false;  
                });  
                $("#btnOK3").click(function() {  
                    $.ajax({  
                        url: "XMLTest.xml",  
                        dataType: 'xml',  
                        success: function(xml) {  
                            $("#list1").html("");  
                            $(xml).find("data>item").each(function() {  
                                $("#list1").append("<li>id:" + $(this).find("id").text() + "</li>");  
                                $("#list1").append("<li>name:" + $(this).find("name").text() + "</li>");  
                            })  
                        },  
                        error: function(result, status) {  
                            alert(status);  
                        }  
                    });  
                    return false;  
                });  
            });   
          
     </script>  
    </head>  
    <body>  
        <form id="form1" runat="server">  
        <div>  
            <input id="btnOK" type="button" value="button" />  
            <input id="btnOK0" type="button" value="button" />  
            <input id="btnOK1" type="button" value="button" />  
            <input id="btnOK2" type="button" value="button" />  
            <input id="btnOK3" type="button" value="button" />  
            <ul id="list"></ul>    
            <ul id="list1"></ul>   
        </div>  
        </form>  
    </body>  
    </html>  
     
    
    using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.Web;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
    using System.Web.Script.Services;  
    using System.Web.Services;  
    using System.Collections;  
      
     
    public partial class 自定义滚动条_JQueryTest : System.Web.UI.Page
        {  
            protected void Page_Load(object sender, EventArgs e)  
            {  
      
            }  
      
            [WebMethod]  
            public static string SayHello()  
            {  
                return "Hello Ajax";  
            }  
      
            [WebMethod]  
            public static string GetStr(string str, string str2)  
            {  
                return str + str2;  
            }  
      
            [WebMethod]  
            public static List<string> GetArray()  
            {  
                List<string> li = new List<string>();  
                for (int i = 0; i < 10; i++)  
                {  
                    li.Add(i + "");  
                }  
                return li;  
            }  
      
            [WebMethod]  
            public static Hashtable GetHash(string key, string value)  
            {  
                Hashtable hs = new Hashtable();  
                hs.Add("www", "yahooo");  
                hs.Add(key, value);  
                return hs;  
            }  
        }  
     
  • 相关阅读:
    HDU 6333.Problem B. Harvest of Apples-组合数C(n,0)到C(n,m)求和-组合数学(逆元)+莫队 ((2018 Multi-University Training Contest 4 1002))
    HDU 6330.Problem L. Visual Cube-模拟到上天-输出立方体 (2018 Multi-University Training Contest 3 1012)
    HDU 6326.Problem H. Monster Hunter-贪心(优先队列)+流水线排序+路径压缩、节点合并(并查集) (2018 Multi-University Training Contest 3 1008)
    杭电1518 Square(构成正方形) 搜索
    POJ1659 Frogs' Neighborhood(青蛙的邻居) Havel-Hakimi定理
    杭电1133 排队买票 catalan
    hdu 5945 Fxx and game 单调队列优化dp
    Codeforces Round #278 (Div. 2) D. Strip 线段树优化dp
    hdu 4348 To the moon 主席树区间更新
    hdu 4417 Super Mario 树状数组||主席树
  • 原文地址:https://www.cnblogs.com/panmy/p/5653898.html
Copyright © 2011-2022 走看看