<form id="form1" runat="server"> <p> 评论:</p> <p> 姓名:<input type="text" name="username" id="username1" /></p> <p> 内容:<textarea name="content" id="content" rows="2" cols="20"></textarea></p> <p> <input type="button" id="send" value="提交" /></p> </form> <div class="comment"> 已有评论:</div> <div id="resText"> </div>
$("#send").click(function () {
$.get("doSave.ashx", {<span style="white-space:pre"> </span> <span style="font-family: Arial, Helvetica, sans-serif;"> </span>//调用json插件
u_name: $("#username1").val(), //json数据/值对化
u_cont: $("#content").val()
}, function (data)
var uName = data.username; //注:此处的username与doSave.ashx中的dic.add("username",uname)中的username相对应的
var uCont = data.content;
var txtHtml = "<div class='comment'><h6>"
+ uName + ":</h6><p class='para'>"
+ uCont + "</p></div>"
$("#resText").html(txtHtml); //将返回的数据添加到页面上
}, "json");
})
<%@ WebHandler Language="C#" Class="doSave" %>
using System;
using System.Web;
public class doSave : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
var dic = new System.Collections.Generic.Dictionary<string, object>(); //存储的集合
string jsonStr = "{}"; //新建字符串jsonStr
context.Response.ContentType = "text/json"; //定义返回的内容类型为json
string uname = context.Request.QueryString[0]; //获取请求参数中第一个参数,也可以直接使用uname
string commet = context.Request.QueryString[1]; //定义字符串uname、commet为context请求查询的字符串context.Request.Params["username"];QyertStrubg:查询字符串
dic.Add("username", uname); //将字符串添加到对象中
dic.Add("content", commet);
jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(dic); //序列化集合为json字符串
context.Response.Write(jsonStr);
}
public bool IsReusable
{
get
{
return false;
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有