Home >
Article > Web Front-end > Javascript reads XML data, displays, edits, and saves it on the page_javascript skills
Javascript reads XML data, displays, edits, and saves it on the page_javascript skills
WBOYOriginal
2016-05-16 18:43:181136browse
First consider what method to use, and consider three methods: 1. C# combines HTML to construct the table, and modification and saving are implemented through Ajax. 2. XML XSL, display and modification are done using two XSL files, and Ajax is used to modify and save the XML. 3. GridView control. After careful consideration, first of all, the third option GridView control cannot meet the needs because XML formats are diverse and may involve a lot of row and column merging and row and column header merging. The first option is too cumbersome. Sitting up requires detailed and physical work, and it is difficult to modify it after the needs change. So choose the second option. Start learning XPath and XSLT. AJAX uses js to asynchronously call the general way of processing files (ashx). 1. An error occurred when implementing the binding of the selection box (reading the database through Ajax and binding data). Finally, it was found that the asynchronous method used when reading XML conflicted with Ajax, which can be solved by synchronization. 2. Save the XML. How to save the modified data to XML? When saving through Javascript, js cannot be saved. If you use js to save, you must use hta; when saving with AJax, how can I pass the modified XML to the AJAX method? After thinking about it, I tried several methods, and I finally tried it. , source code js:
<%@ WebHandler Language="C#" Class="getDataSet" %> using System; using System.Web; using System.Data; using System.Data.SqlClient; using System.Text; using DHCC.HISHR.BO; public class getDataSet : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string result = ""; string table = context.Request.Params["table"].ToString().Trim(); string value = context.Request.Params["value"].ToString().Trim(); string text = context.Request.Params["text"].ToString().Trim(); string sql = "SELECT " value "," text " FROM HISHR." table " "; BOSQLExecuter SQLexec = new BOSQLExecuter(); DataSet ds = SQLexec.GetDataSetSQLExecuter(sql); if (ds != null) if (ds.Tables.Count > 0) { DataTable dt = ds.Tables[0]; foreach (DataRow dr in dt.Rows) { result = "$" dr[value].ToString() "^" dr[text].ToString(); } if (result.Length > 0) result = result.Substring(1); } //根据HTTP局部请求返回流到页面 context.Response.Write(result); } public bool IsReusable { get { return false; } } }
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn