日期:2014-05-17  浏览次数:20441 次

php中嵌套Ajax脚本,运行时什么都没有出现
客户端代码:
<html>
 <head>
  <title>Information</title>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  <script type="text/javascript">
var xmlHttp ;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP") ;
}else if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest() ;
}
}
function check(){
createXMLHttpRequest() ;
var name=document.getElementById("name").value ;
var author=document.getElementById("author").value ;
var pl=document.getElementById("publisher") ;
var publisher=pl.options[pl.selectedIndex].text ;
var isbn=document.getElementById("isbn").value ;
var tp=document.getElementById("type") ;
var publisher=tp.options[tp.selectedIndex].text ;
var price=document.getElementById("price").value ;

var str="name="+name+"&author="+author+"&publisher="+publisher+"&isbn="+isbn+"&type="+type+"&price="+price ;
var url="addsend.php" ;
xmlHttp.open("POST" , url , true) ;
xmlHttp.onreadystatechange=callback ;
xmlHttp.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded") ;
xmlHttp.send(str) ;

}
function callback(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
var str1=xmlHttp.responseText ;
if(str1=="1"){
alert("图书数据成功添加") ;
window.location.reload() ;
}
}
}
}
  </script>
 </head>

 <body>
  <h2 align="center">添加图书</h2>
  <p align="center"><a href="index.php">显示信息</a>|<a href="update.php">数据修改</a>|<a href="del.php">数据删除</a>
  </p>

 <form name="myform">
<table align="center">
<tr><td>图书名称:</td><td><input type="text" id="name"></td></tr>
<tr><td>图书作者:</td><td><input type="text" id="author"></td></tr>
<tr><td>出版社:</td><td><select id="publisher"><option>清华大学出版社</option><option selected>人民邮电出版社</option><option>电子工业出版社</option><option>河南出版社</option></select></td></tr>
<tr><td>ISBN号:</td><td><input type="text" id="isbn"></td></tr>
<tr><td>图书类型:</td><td><select id="type"><option selected>计算机类图书</option><option>经济类图书</option><option>财经类图书</option><option>哲学类图书</option><option>旅游类图书</option></select></td></tr>
<tr><td>图书价格:</td><td><input type="text" id="price"></td></tr>
<tr><td align="center" colspan="2"><input type="button" value="OK" onclick="return check()">&nbsp;&nbsp;&nbsp;<input type="reset" value="重置"></td></tr>
</table>
 </form>
 </body>
</html>

服务器:
<?php
header("Content-Type:text/html ; chareset:gb2312") ;
$name=$_POST["name"] ;
$author=$_POST[&q