b.ashx后台处理程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DTcms.Common;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using DTcms.DBUtility;
namespace DTcms.Web
{
/// <summary>
/// b 的摘要说明
/// </summary>
public class b : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
//string namex= DTRequest.GetQueryString("namex");
string namex = DTRequest.GetFormString("namex");
string password = DTRequest.GetFormString("password");
//context.Response.Write("insert into t (namex,password) values ('" + namex + "','" + namex + "')");
//context.Response.End();
//context.Response.Write(password);
int aa=DbHelperSQL.ExecuteSql("insert into t (namex,password) values ('" + namex + "','" + password + "')");
if (aa>0) //写入数据库成功
{
context.Response.Write("{\"zt\":1,\"xx\":\"添加成功啦\"}");
}
else
{
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
前台简单提交例子
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form method="get" action="b.ashx">
<input id="hhhh" name="namex" type="text" value="" />
<input name="password" type="password" value="" />
<input type="submit" value="提交" />
</form>
</body>
</html>
前台ajax提交的例子
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<script type="text/javascript" src="http://www.kanmogu.com/scripts/jquery/jquery-1.10.2.min.js"></script>
<body>
<script type="text/javascript">
$(function () {
//alert("初始化");
});
function tj() {
alert($("#namex").val());
$.ajax({
type: "POST",
url: "b.ashx",
dataType: "json",
timeout: 20000,
data: {
"namex": $("#namex").val(), //
"password": $("#password").val(), //
},
beforeSend: function () {
$("#tjq").append("<img src=http://www.yn137.com/images/newlogo.gif >");
alert("提交前");
},
success: function (data, textStatus) {
if (data.zt == 1) {
$("#tjq").hide();
alert(data.zt);
alert(data.xx);
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
//alert("错误");
//alert(XMLHttpRequest.status);
//alert(XMLHttpRequest.readyState);
//alert(textStatus); // paser error;
}
});
}
</script>
<div id="tjq"></div>
<input name="namex" id="namex" type="text" value="" />
<input name="password" type="password" value="" />
<input type="submit" onclick="tj()" value="提交" />
</body>
</html>
Copyright © 2004-2024 Ynicp.com 版权所有 法律顾问:建纬(昆明)律师事务所 昆明市网翼通科技有限公司 滇ICP备08002592号-4