日期:2014-05-16 浏览次数:20755 次
最近在看php和ajax,就测试一下总是报错,不知道是什么原因?
?
ajax_test.html代码:
<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
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("myDiv").innerHTML=xmlhttp.responseText;
}
}
var custname = document.getElementByName("custname");
xmlhttp.open("GET","mssql.php?custname="+custname,true);
xmlhttp.send();
}
</script>
</head>
<body>
<h2>AJAX</h2>
<input type="text" name="custname" onKeyUp="loadXMLDoc()" onClick="loadXMLDoc()"/>
<div id="myDiv"></div>
</body>
</html>
?
然后就是mssql.php
<?php $custname = $_GET["custname"]; $conn = mssql_connect("192.168.6.3,1433","sa","") or die("Coulde not connection mssql"); mssql_select_db("LKcrm",$conn); echo("输入值:" . $custname . "<br/>"); $query = "select * from customer where custname like '%".$custname."%' "; echo("执行的SQL语句:" . $query . "<br/>"); $result = mssql_query($query); $row_num = mssql_num_rows($result); echo("以下是查询出来的结果:<br/>"); for($i=0;$i<$row_num;$i++) { $row = mssql_fetch_array($result); echo($row["custname"]); echo("<br/>"); } mssql_close($conn); ?>
??
这个php的代码是没有错误的,我测试过了,开启服务器,在IE中输入? http://localhost/mssql.php?custname=寮步 ,就是直接给custname赋值为“寮步”,就能查出数据,如图所示:
?
?但使用ajax_test.html调用这个php的时候就出现问题,拒绝访问,错误如下图:
?如果谁以前遇到过这个问题,请告诉我怎么解决,谢谢了!