我已经发布了以下代码。 有两个文件..
sales.htm
<script type='text/javascript'>
function getname()
{
var vendorID = document.getElementById("idvid").value;
var xmlhttp;
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)
{
document.getElementById("iddiv1").innerHTML=xmlhttp.responseText;
document.getElementById("iddiv2").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getvendorname.php?vendorid="+vendorID,true);
xmlhttp.send();
}
</script>
<html>
<head><title>vendor info</title> </head>
<body>
<td>Vendor Primary ID:</td>
<td><input type="text" id="idvid" name="vendor_primary_number" onblur="getname()">
</td>
<td> <div id="iddiv1"> </div></td>
<td> <div id="iddiv2"> </div></td>
</body>
</html>
getvendorname.php
<?php
$vid = $_GET['vendorid'];
$connection = mysql_connect('localhost','root','root');
mysql_select_db('bgm_score', $connection);
$r ="select vendorid,vendorname from vendor_info where vendorid ='$vid'";
$result = mysql_query($r, $connection);
$row = mysql_fetch_assoc($result);
echo $row["vendorid"];
echo $row["vendorname"];
?>
答案 0 :(得分:1)
我对您的代码进行了一些更正以使其正常工作。首先,替换这一行:
ergm(GY2~graphletCount(n))
使用:
document.getElementById("iddiv1").innerHTML=xmlhttp.responseText;
原因是您不需要从数据库中检索供应商ID,因为这是您要发送的数据。只需使用您拥有的变量即可。这也意味着您需要更改PHP代码。
从查询中删除vendorid字段:
document.getElementById("iddiv1").innerHTML=vendorID;
现在看起来像这样:
$r ="select vendorid,vendorname from vendor_info where vendorid ='$vid'";
同时删除此行,因为不需要:
$r ="select vendorname from vendor_info where vendorid ='$vid'";