0
我試圖做一個函數發送一個XMLHttpRequest
並返回一個字符串與響應的內容,但它總是返回null
。我該如何解決?XMLHttpRequest字符串
代碼:
function getPage() { if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); } xmlhttp.open('GET','page.php',false); xmlhttp.send(); xmlDoc = xmlhttp.responseXML; if ($.browser.msie) return xmlDoc.xml; else return (new XMLSerializer()).serializeToString(xmlDoc); }
問題1:您使用的是什麼瀏覽器?有兩種不同的代碼路徑。 問題2:既然看起來你在使用JQuery,爲什麼不使用$ .get()? – Talljoe 2011-04-02 17:15:18
我在jQuery中使用$ .ajax(),因爲它提供了更多選項。然後你可以擁有一個成功,完成和錯誤的聽衆,看看你的問題是什麼。 – tjameson 2011-04-02 17:22:54
我正在使用jQuery。實際上,我可以使用'xmlhttp.responseText'而不是'xmlhttp.responseXML'。 '$ .get()'異步嗎? – xsznix 2011-04-02 17:23:34