xmlhttp.open("GET","admin/getmarket.php?q="+str2+"&loc="+loc,true);
getmarket.php
中的代码,它从变量$title and $txt1
中获取数据库中的数据。这是通过php echo
继续javascript中的代码,
var td1 = document.getElementById('tmp-data1').innerHTML;
document.getElementById("databox1").innerHTML = td1;
不起作用。
是否有任何帮助?答案 0 :(得分:0)
您需要从ajax响应中获取数据。读取onreadystatechange事件监听器中的xmlhttp.responseText,然后尝试设置该值。
以下示例代码。
var xmlhttp= new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("databox1").innerHTML = xmlhttp.responseText['tmp-data1']; // Change this line following your response structure
}
};
xmlhttp.open("GET","admin/getmarket.php?q="+str2+"&loc="+loc,true);
xmlhttp.send();