目前来说,使用JSON保存数据比较方便,前台可以不用Test.aspx 页面,可以直接用Html页面,使用.aspx页面的弊端就不在这里熬述。

具体步骤如下:

 

1、新建一个Html页面,命名为Test.html
 1 <script type="text/javascript" src="easyui/jquery.min.js"></script>
 2 <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
 3 <script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>
 4 <script type="text/javascript" src="js/save.js"></script>
 5 <link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css" />
 6 <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css" />
 7 
 8   <div>
 9     <input type="text" id="txtFileNames" class="textbox" name="Vassets" style="width:110px;"/>
10     <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="objV.saves()">保存</a> 
11   </div>

 

 

2、新建一个JS页面,命名为save.js
 1 objV = {
 2         saves:function(){
 3             $.ajax({
 4                 type: "POST",
 5                 url: "Test.ashx",
 6                 contentType: "application/json; charset=utf-8",
 7                 data: JSON.stringify(GetJsonData()),
 8                 dataType: "json",
 9                 success: function (message) {
10                     if (message > 0) {
11                         alert("请求已提交!我们会尽快与您取得联系");
12                     }
13                 },
14                 error: function (message) {
15                     $("#request-process-patent").html("提交数据失败!");
16                 }
17             });
18         
19         }
20 
21     };
22 
23 
24     function GetJsonData() {
25         var json = {
26             "FTName": $("#txtFileNames").val()
27         };
28         return json;
29     }

 

 

3、新建一个AddTest.ashx页面
 1         int num = 0;
 2             context.Response.ContentType = "application/json";
 3             var data = context.Request;
 4             var sr = new StreamReader(data.InputStream);
 5             var stream = sr.ReadToEnd();
 6             var javaScriptSerializer = new JavaScriptSerializer();
 7             var PostedData = javaScriptSerializer.Deserialize<Model.FileType>(stream);
 8             DataAccess<Model.FileType> da = new DataAccess<Model.FileType>();
 9             
10             
11 
12             try
13             {
14                 num = da.Add(PostedData, "FileType");
15             }
16             catch (Exception msg)
17             {
18                 context.Response.Write(msg.Message);
19             }
20 
21             context.Response.ContentType = "text/plain";
22             context.Response.Write(num);