使用ajax获取数据; PHP

时间:2013-01-17 08:39:36

标签: javascript php ajax

当我从组合框中选择一个名字时,我正在这样做,那么应该使用ajax从mysql表中显示与所选名称相关的数据。但它无法完成。

<html>
<head>
<script>
function showUser (str)
{
    if(str=="")
    {
        document.getElementById("txtHint").innerHTML=="";
        return;
    }
    if(window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmltttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById("txtHint").innerHTML=xmlhttp.responseText;

        }
    }
    xmlhttp.open("GET","getuser.php?q="+str,true);
    xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="users" onchange="""showUser(thiis.value)">
<option value="">Select a person</option>
<option value="1">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Glenn Quagmire</option>
<option value="4">Joseph Swanson</option>
</select>
</form>
<br>
<div id="txtHint">Person List is Here</div>
</body>
</html>

它显示了一个通知

1 个答案:

答案 0 :(得分:3)

那是因为您没有读取CSV文件,您显示的数据的字节模式表明包含BIFF数据的OLE包装器....即。它可能是一个真正的Excel .xls文件。尝试在MS Excel中打开文件(必要时重命名为.xls)或Gnumeric或Open / Libre Office Calc。

要在PHP中处理文件,您需要一个能够读取Excel xls文件的PHP库:除了PHPExcel之外,您还可以找到其他库here的列表。