不知道怎么搞`大家看下!谢谢(在线等了!解决了就结贴)
用ajax!
我现在是想从后台数据库中读出一行数据!包括(姓名,年龄……)!
在这里我从后台应该返回一个什么类型的方法?
并且在前台用javascript 怎么分别读出里面的值``!
我现在的情况是如果后台只返回一个单一的记录(string ,int……)这样的我会处理了!就是不知道如果想返回和接收一组数据怎么办!
路过的指点一下!谢谢``!
[解决办法]
返回 text/xml,
responseXML可处理!
[解决办法]
如下例:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<html>
<head>
<title> XMLHttp Example 1 </title>
<script type= "text/javascript "src= "zxml.js "> </script>
<script type= "text/javascript ">
function requestCustomerInfo() {
var sId = document.getElementById( "txtCustomerId ").value;
var oXmlHttp = zXmlHttp.createRequest();
oXmlHttp.open( "get ", "GetCustomerData.php?id= " + sId, true);
oXmlHttp.onreadystatechange = function () {
if (oXmlHttp.readyState == 4) {
if (oXmlHttp.status == 200) {
displayCustomerInfo(oXmlHttp.responseText);
} else {
displayCustomerInfo( "An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
}
}
};
oXmlHttp.send(null);
}
function displayCustomerInfo(sText) {
var divCustomerInfo = document.getElementById( "divCustomerInfo ");
divCustomerInfo.innerHTML = sText;
}
</script>
</head>
<body>
<p> Enter customer ID number to retrieve information: </p>
<p> Customer ID: <input type= "text " id= "txtCustomerId " value= " " /> </p>
<p> <input type= "button " value= "Get Customer Info " onclick= "requestCustomerInfo() " /> </p>
<div id= "divCustomerInfo "> </div>
</body>
</html>
[解决办法]
可以返回dataset