日期:2014-05-16 浏览次数:20843 次
function Xml() { // XHR = window.XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP"); if (window.ActiveXObject) { XHR = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest) { XHR = new XMLHttpRequest(); } if (XHR != null) { XHR.open("GET", "../Tools/js_json.ashx", true); XHR.onreadystatechange = function () { if (XHR.readyState == 1) { alert("1"); } if (XHR.readyState == 2) { alert("2"); } if (XHR.readyState == 3) { alert("3"); } if (XHR.readyState == 4) { if (XHR.status == 200) { // var text = XHR.responseText; // alert(text); alert("zm"); var xmlobj = XHR.responseXML; // XHR.load("channel.xml"); var items, title, content; items = xmlobj.getElementsByTagName("item"); title = items[0].getElementsByTagName("title")[0].childNodes[0].nodeValue; content = items[0].getElementsByTagName("content")[0].firstChild.data; document.getElementById("title").innerHTML = title; document.getElementById("content").innerHTML = content; } } } XHR.send(null); } }
StringBuilder sb = new StringBuilder(); sb.Append("<?xml version=\"1.0\" encoding=\"gb2312\" ?>"); sb.Append("<channel>"); sb.Append("<item>"); sb.Append("<title>Ajax study</title>"); sb.Append("<content>XmlHttpRequest开发实例</content>"); sb.Append("</item>"); sb.Append("</channel>"); context.Response.ContentType = "text/xml"; context.Response.Write(sb.ToString());
context.Response.Charset = "gb2312";/////////加这句试试 context.Response.ContentType = "text/xml"; context.Response.Write(sb.ToString());
------解决方案--------------------
context.Response.Clear();
context.Response.ContentType = "Text/HTML";
context.Response.ContentEncoding = Encoding.GetEncoding("gb2312");
context.Response.Write(sb.ToString());
你后台确定一下格式试试 我一直都用接口 都没问题啊