2013-12-21 44 views
-1

下面是给出该错误的代码。不允许的关键字符在我的代码中出错

<html> 
<head> 
<script type="text/javascript"> 

var d = new Date(); 
var date = d.toLocaleString(); 

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; 
} 
} 
xmlhttp.open("GET","test.php?date"+date,true); 
xmlhttp.send(); 

</script> 
</head> 
<body> 
<div id ="myDiv"></div> 
</body> 
</html>  

这里是php代码。

<?php 

$date = $_GET['date']; 

echo $date; 

?> 
+0

soooooo有什么问题吗? –

+0

请给我们显示错误.. –

回答

0

替换此线,然后再试一次

xmlhttp.open("GET","test.php?date="+date,true); 
1

的错误是查询字符串

xmlhttp.open("GET","test.php?date"+date,true); 
            ^^^^ 

它缺少名称和值之间的=,添加=和服务器会停止抱怨它不知道日期[DateString]在GET参数中是什么日期

xmlhttp.open("GET","test.php?date="+date,true); 
           ^

更好的对其进行编码

xmlhttp.open("GET","test.php?date="+encodeURIComponent(date),true); 
           ^
相关问题