c# 后台取jQuery Ajax中的复杂参数问题
页面文件<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestjQueryajax.aspx.cs" Inherits="OA.Web.Test.TestjQueryajax" %>
<!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 runat="server">
<title></title>
<script src="../JS/JQuery/jquery-1.4.4.js" type="text/javascript"></script>
<script type="text/javascript">
function TestjQueryAjax() {
$.ajax({
type: "post",
dataType: "text",
contentType: "application/json",
data: {data:5,name:"admin"},
url: "TestjqueryajaxHandler.ashx",
success: function (result) { alert(result); },
error: function (e) { alert(e.responseText); }
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" value="testjqueryajax" onclick="TestjQueryAjax()" />
</div>
</form>
</body>
</html>
后台代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.Script.Serialization;
namespace OA.Web.Test
{
/// <summary>
/// TestjqueryajaxHandler 的摘要说明
/// </summary>
public class TestjqueryajaxHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
byte[] datas = new byte[context.Request.ContentLength];
context.Request.InputStream.Read(datas, 0, context.Request.ContentLength);
string str = Encoding.UTF8.GetString(datas);
context.Response.Write("Hello World");
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
//取到 data=5&name=admin 这么个东西怎么搞啊