我在使用Javascript的代碼中使用AJAX調用。使用Javascript解析HTML中的AJAX resposne
function loadFacility(callback)
{
//alert('In loadFacility');
var xmlhttp;
var keys=document.firstCallInformation.facilityselect.value;
var urls="http://localhost:8080/webfdms/showFirstCallInformation.do?vitalsId=366";
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status == 200)
{
//var some=xmlhttp.responseXML.documentElement;
var response = xmlhttp.responseText;
console.log(response)
callback(xmlhttp.responseText);
}
}
xmlhttp.open("GET",urls,true);
xmlhttp.send(null);
}
function loadFacilityCallback(response){
if(response != null){
//alert(response);
console.log(response);
var div = document.createElement("div");
div.innerHTML = response;
document.getElementById("facilityselect").innerHTML = div.querySelectorAll("select#facilityselect");;
}
編輯: 我已經更新了我的回調函數。但是在這裏,我收到了選擇列表作爲[Object Nodelist]。現在我怎樣才能在我的HTML中顯示?
在回調函數中,我現在收到了HTML的響應,我想解析該HTML響應,以便我可以進一步處理它。我使用普通的JavaScript來做到這一點。請任何人告訴我如何解析作爲HTML收到的Ajax響應。
基本上我想從解析的html中獲取選擇標記並將其顯示在頁面上。並有許多選擇標籤。所以我如何獲取它? –
我更新了答案。 – Barmar
我想從所有選擇標籤的列表中取出特定的選擇標籤? –