要写一个WebService,说完需求后感觉是要通过输入的值获取对应信息,所以就想创建一个含有键值对的list通过ajax来获取值,但不知道该怎么写求大佬们指点
下面是代码残局using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;namespace WebApplication1
{
/// <summary>
/// test 的摘要说明
/// </summary>
public class test : IHttpHandler
{
[WebMethod]
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/json";
string number1 = context.Request["aaa"];
//var result = Int32.Parse(number1) + Int32.Parse(number2);
List<string> strList = new List<string>();
strList.Add("qwer");
strList.Add("w3c");
if (context.Request.QueryString["number1"] == " 53014")
context.Response.Write("result is" + " " + strList);
}
// [WebMethod(Description = "list")]
//public void Kh(HttpContext context, string a)
//{
// context.Response.ContentType = "text/plain";
// string number1 = context.Request["aaa"]; // List<string> strList = new List<string>();
// strList.Add("商品名称,商品颜色");
// //if (number1 == "53014")
// // context.Response.Write(strList);
// //return strList;
//}
public bool IsReusable
{
get
{
return false;
}
}
}}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LoginGet.aspx.cs" Inherits="WebApplication1.LoginGet" %><!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="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script>
function callAjax() {
$.ajax({
type: "POST", //提交方式
url: "/test.ashx",//路径
data: {
"aaa": $("#number1").val(),
},
success: function (result) {//返回数据根据结果进行相应的处理
alert(result);
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<label>请输入编号</label> <input type="number" name="number1" id="number1" />
<input type="button" value="Add" onclick="callAjax();" />
</div>
</form>
</body>
</html>
下面是代码残局using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;namespace WebApplication1
{
/// <summary>
/// test 的摘要说明
/// </summary>
public class test : IHttpHandler
{
[WebMethod]
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/json";
string number1 = context.Request["aaa"];
//var result = Int32.Parse(number1) + Int32.Parse(number2);
List<string> strList = new List<string>();
strList.Add("qwer");
strList.Add("w3c");
if (context.Request.QueryString["number1"] == " 53014")
context.Response.Write("result is" + " " + strList);
}
// [WebMethod(Description = "list")]
//public void Kh(HttpContext context, string a)
//{
// context.Response.ContentType = "text/plain";
// string number1 = context.Request["aaa"]; // List<string> strList = new List<string>();
// strList.Add("商品名称,商品颜色");
// //if (number1 == "53014")
// // context.Response.Write(strList);
// //return strList;
//}
public bool IsReusable
{
get
{
return false;
}
}
}}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LoginGet.aspx.cs" Inherits="WebApplication1.LoginGet" %><!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="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script>
function callAjax() {
$.ajax({
type: "POST", //提交方式
url: "/test.ashx",//路径
data: {
"aaa": $("#number1").val(),
},
success: function (result) {//返回数据根据结果进行相应的处理
alert(result);
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<label>请输入编号</label> <input type="number" name="number1" id="number1" />
<input type="button" value="Add" onclick="callAjax();" />
</div>
</form>
</body>
</html>
解决方案 »
- vs与SQL 2005连接问题
- 数据库远程连接问题
- gridview怎么用包括分页读取数据
- 一个猜想。。
- 关于数字字符串处理一个小问题(刚学C#)
- System.Security 命名空间 看不懂啊。 哪位大哥能帮助下我。 这些东西例子也没有。 什么都没有。 因为我应聘要用到。 现在我还不知道怎么
- 在调用了BindingManagerBase.EndCurrentEdit()方法后,使用用DbDataAdapter.Update()方法提交数据库,为什么当前的DataGridCell的数据
- 在网页跳转前的script对话框无法显示问题~!
- 如何判断一个按钮点击两次
- win forms中关于DataGrid的问题
- 模糊查询的数据为啥不显示
- 无法将bool隐式转化为类型int
使用 json.net库