C# .Net HttpListenerRequest响应无法在chrome中使用Ajax
在我的代码中,我执行以下操作:C# .Net HttpListenerRequest响应无法在chrome中使用Ajax,c#,javascript,ajax,google-chrome,C#,Javascript,Ajax,Google Chrome,在我的代码中,我执行以下操作: response.ContentType = "text/xml"; StringWriter stringToWrite = new StringWriter(); respose_example = getData(); System.Xml.Serializati
response.ContentType = "text/xml";
StringWriter stringToWrite = new StringWriter();
respose_example = getData();
System.Xml.Serialization.XmlSerializer outSeralizeList = new System.Xml.Serialization.XmlSerializer(typeof(List<Registers>));
outSeralizeList.Serialize(stringToWrite, respose_example);
string responseString = stringToWrite.ToString();
// Construct a response.
response.ContentEncoding = System.Text.Encoding.UTF8;
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
// Get a response stream and write the response to it.
response.ContentLength64 = buffer.Length;
Stream output = response.OutputStream;
output.Write(buffer, 0, buffer.Length);
// You must close the output stream.
output.Close();
xmlhttp.open("POST", "", false);
var command = new commandObject();
command.command = "xml";
try {
xmlhttp.send(JSON.stringify(command));
} catch(e){
alert(e);
}
我不断地发现这个错误:
DOMException {message: "A network error occurred.", name: "NetworkError", code: 19, stack: "Error: A network error occurred.↵ at getXML (ht…rElement.onclick (http://127.0.0.1:7000/:403:164)", INDEX_SIZE_ERR: 1…}
code: 19
message: "A network error occurred."
name: "NetworkError"
stack: "Error: A network error occurred.↵ at getXML (http://127.0.0.1:7000/:84:19)↵ at create_table (http://127.0.0.1:7000/:182:22)↵ at HTMLAnchorElement.onclick (http://127.0.0.1:7000/:403:164)"
__proto__: DOMException
不知道为什么它在FF中工作。我希望chrome能提供更多细节。在重新编写代码并使用异步ajax调用之后,chrome似乎可以工作。我想chrome上的同步Ajax已经坏了。将asynch设置为false是个坏主意。改用回调/承诺。如果在firefox(带有firebug)和Chrome中按F12,并在控制台中查看xhr请求。你能看到后教育价值观有什么不同吗?