0

这是我的 html/ajax 代码

<head>
<script language="javascript" type="text/javascript">
<!-- 
//Browser Support Code
function ajaxFunction(){
var ajaxRequest;  // The variable that makes Ajax possible!

try{
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
} catch (e){
    // Internet Explorer Browsers
    try{
        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try{
            ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e){
            // Something went wrong
            alert("Your browser broke!");
            return false;
        }
    }
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
    if(ajaxRequest.readyState == 4){
        var ajaxDisplay = document.getElementById('ajaxDiv');
        ajaxDisplay.innerHTML = ajaxRequest.responseText;
    }
}
var date = document.getElementById('Date').value;
var queryString = "?date=" + date;
ajaxRequest.open("GET", "php.php" + queryString, true);
ajaxRequest.send(null); 
}

//-->
</script>

<!--showDate AJAX script -->

<!-- //Calender Script -->
<link rel="stylesheet" type="text/css" media="all"   href="scripts/jsDatePick_ltr.min.css"/>

<!--JavaScript-->
<script type="text/javascript" src="scripts/jsDatePick.min.1.3.js"></script>

<!--For javascript Calendar-->  
<script type="text/javascript">
window.onload = function(){
new JsDatePick({useMode:2, target:"Date", cellColorScheme:"orange", dateFormat:"%d-%m-%Y",});};
</script>
</head>
<body>
<form action=""> 
Date &nbsp;:&nbsp; <input type="text" size="20" id="Date" name="Date"/>
<input type="submit" name="submit" value="Submit" onClick="ajaxFunction()"/>
</form>
<div id="ajaxDiv">Time slots will be listed here...</div>

</body>

这是我的 PHP 代码

<?php

$d = $_GET['date'];
$timestamp = strtotime($_GET['date']);
$date = date("Y-m-d",$timestamp);

echo "Time is $date";
?>

我可以从日历中选择日期,日期将显示在下面。不幸的是,它不起作用。有人请帮我解决我的问题。我已经尝试了很多次来修复错误,但仍然无法做到。差点晕倒。

4

2 回答 2

0

首先,我建议您使用jQuery 进行 Ajax 处理,那么您到底为什么要查询服务器以获取日期,传递日期本身呢?

使用moment.jsxdate进行客户端日期时间格式。

于 2012-11-14T16:35:33.373 回答
0

你想做什么和你正在做什么是两件非常不同的事情,1.你根本不需要php。2.这是完整的代码供您复制。http://www.java2s.com/Code/JavaScript/Development/UpdateTimepersecond.htm

于 2012-11-14T19:19:27.790 回答