ASP .NET 使用Ajax

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tsoTeo/article/details/79163730

TTTT.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TTTT.aspx.cs" Inherits="DpdsSystem.TTTT" %>

<!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="Scripts/jquery.min.js" ></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <button onclick="fun()">NANIU</button>
    </div>
    </form>
</body>
    <script>
        function fun() {
            $.ajax({
                type: "post",
                contentType: "application/json; charset=utf-8",
                dataType: "text",//返回数据类型
                url: "TTTT.aspx/selectdb",//发送到后台的某个方法
                data: "{'id':'nihao','name':'Halo'}",//代表团ID
                success: function (result) {
                    alert(result);
                    var sss = eval('(' + result + ')');
                    //alert(sss.id);//返回的数组结果
                },
                error: function () {
                    alert("发送失败!");
                }
            });
        }
    </script>
</html>
TTTT.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DpdsSystem
{
    public partial class TTTT : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        [WebMethod]
        public static string selectdb(string id,string name)
        {
            return id+ " ,Hello, " + name;
        }
    }
}



猜你喜欢

转载自blog.csdn.net/tsoTeo/article/details/79163730