2013-12-21 43 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); 
           ^
相關問題