EasyUI saves data in JSON and easyuijson
Currently, it is convenient to store data in JSON format. The Test. aspx page can be used directly on Html pages without the need for the front-end. the disadvantages of using the. aspx page are not described here.
The procedure is as follows:
1. Create a new HTML page named 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 () "> Save </a> 11 </div>
2. Create a New JS page named 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 ("request submitted! We will contact you as soon as possible "); 12} 13}, 14 error: function (message) {15 $ ("# request-process-patent" 2.16.html ("failed to submit data! "); 16} 17}); 18 19} 20 21}; 22 23 24 function GetJsonData () {25 var json = {26" FTName ": $ ("# txtFileNames "). val () 27}; 28 return json; 29}
3. Create an AddTest. ashx page.
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 try13 {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);