我的一个脚本有问题。服务器在 php 中运行,我使用 AJAX 发布数据。这是我的脚本。
PHP 脚本:
<?php
include './connConf.php';
if (isset($_POST['pStr'])){
$preStr=$_POST['pStr'];
$query="SELECT * FROM advisory WHERE projname in (SELECT projname FROM advisorydata WHERE prefixStr LIKE '%$preStr')";
$result=mysql_query($query);
$num=mysql_numrows($result);
if ($num > 0){
echo "<font style=\"font-size:12px\" color=\"#FF6820\" face=\"Century Gothic\"><b>Search Result :</b></font><br><br>";
for ($x=0;$x<$num;$x+=1){
echo "<font style=\"font-size:12px\" color=\"#FFFFFF\" face=\"Century Gothic\">Project Name:   </font><font style=\"font-size:11px\" color=\"#C0FFFF\" face=\"Century Gothic\"><b>".mysql_result($result,$x,"projname")."</b></font><br>";
echo "<font style=\"font-size:12px\" color=\"#FFFFFF\" face=\"Century Gothic\">APMS ID:   </font><font style=\"font-size:11px\" color=\"#C0FFFF\" face=\"Century Gothic\"><b>".mysql_result($result,$x,"apmsid")."</b></font><br>";
echo "<font style=\"font-size:12px\" color=\"#FFFFFF\" face=\"Century Gothic\">Prefix/es:   </font><font style=\"font-size:11px\" color=\"#C0FFFF\" face=\"Century Gothic\"><b>".mysql_result($result,$x,"projprefix")."</b></font><br>";
echo "<font style=\"font-size:12px\" color=\"#FFFFFF\" face=\"Century Gothic\">Usage Type:   </font><font style=\"font-size:11px\" color=\"#C0FFFF\" face=\"Century Gothic\"><b>".mysql_result($result,$x,"usagetype")."</b></font><br>";
echo "<font style=\"font-size:12px\" color=\"#FFFFFF\" face=\"Century Gothic\">Rate:   </font><font style=\"font-size:11px\" color=\"#C0FFFF\" face=\"Century Gothic\"><b>".mysql_result($result,$x,"projrate")."</b></font><br>";
echo "<font style=\"font-size:12px\" color=\"#FFFFFF\" face=\"Century Gothic\">Offer Details:   </font><font style=\"font-size:11px\" color=\"#C0FFFF\" face=\"Century Gothic\"><b>".mysql_result($result,$x,"offerdetails")."</b></font><br><br>";
}
}else{
echo "<font style=\"font-size:12px\" color=\"#FFFFFF\" face=\"Century Gothic\">No results found ...</font>";
}
}else{
echo "<font style=\"font-size:12px\" color=\"#FFFFFF\" face=\"Century Gothic\">Problems encountered while processing the data ...</font>";
}
?>
JS脚本:
function QueryPrefix()
{
var xmlhttp;
var pStr = document.getElementById('Editbox2');
var htmlHolder = document.getElementById('Html1');
var butStr = document.getElementById('Button1');
if (pStr.value.length == 0){
alert("Please enter a value on the box provided!");
return;
}
pStr.value="";
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)
{
htmlHolder.innerHTML=xmlhttp.responseText;
butStr.disabled=false;
}
}
butStr.disabled=true;
xmlhttp.open("POST","searchutype.php",false);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("pStr=" + pStr.value);
}