js前端操作,c#后端下发xml文件
前端:
var xmlLanguageDoc;
$.ajax({
        url: "/GiveMeXML",//此处可随意定义,不一定是路径。在c# ,请求被捕获后,由c#读取本地文件,然后写入Response
        dataType: 'xml',
        type: 'GET',
        error: function(xml)
        {
        },
        success: function(xml)
        {
            xmlLanguageDoc=xml;
        }
    });
c#:
HttpListenerContext nowContext = MainHttpsListener.EndGetContext(ar);
HttpListenerRequest request = nowContext .Request;
HttpListenerResponse response = nowContext .Response;
string recived = request.RawUrl;
System.IO.Stream output = response.OutputStream;
if(recived.Contains("GiveMeXML"))
{
 if (File.Exists("........\\some.xml"))
                        {
                            response.ContentEncoding = Encoding.UTF8;
                            response.ContentType = "text/xml;charset=utf-8";
byte[] Rtn = File.ReadAllBytes(".......\\some.xml");
                            response.StatusCode = 200;
                            if (output.CanWrite && response.KeepAlive) { try { try { output.Write(Rtn, 0, Rtn.Length); } catch { } } catch { } }
                        }
}
output.Close();
xml文件

js:
 
languageNodeList为German下所有的节点,在each()中,$(this)为每一个item的属性值
 
                     
                    
                 
                    
                 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号