2013-10-30 27 views
0

使用Ajax的工作在我的代碼我做了以下內容:淨HttpListenerRequest響應沒有在Chrome

     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的作品上。我希望鉻會提供更多的細節。

+0

將異步設置爲false是個壞主意。改爲使用回調/承諾。如果您在firefox(使用螢火蟲)和Chrome中按F12,並在控制檯中查看xhr請求。你能看到POST ed值有什麼不同嗎? – HMR

回答

0

重新編碼我的代碼並使用異步ajax調用chrome似乎工作。我想在Chrome上同步Ajax是打破的。