Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么我不能得到更多的时间?_Php_Javascript_Ajax - Fatal编程技术网

Php 为什么我不能得到更多的时间?

Php 为什么我不能得到更多的时间?,php,javascript,ajax,Php,Javascript,Ajax,PHP文件的代码: <html> <head> <title>Ajax Demonstration</title> <style> .displaybox { width:150px; background-color:#ffffff; border:2px solid #000000; padding:10px; font:24px normal verdana, helvetica, arial, sans-serif; } <

PHP文件的代码:

<html>
<head>
<title>Ajax Demonstration</title>
<style>
.displaybox {
width:150px;
background-color:#ffffff;
border:2px solid #000000;
padding:10px;
font:24px normal verdana, helvetica, arial, sans-serif;
}
</style>
<script language="JavaScript" type="text/javascript">
//<%=new java.util.Date()%>

function getXMLHTTPRequest() {
    alert("Hello! I am an alert box!");
    try {
        req = new XMLHttpRequest();
    } catch (err1) {
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (err2) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (err3) {
                req = false;
            }
        }
    }
    return req;
}
var http = getXMLHTTPRequest();

function getServerTime() {
    var myurl = 'http://localhost/csp 2/telltimeXML.php';
    myRand = parseInt(Math.random() * 999999999999999);
    // var modurl = myurl+"?rand="+myRand;
    http.open("GET", myurl, true);
    http.onreadystatechange = useHttpResponse;
    http.send(null);
}

function useHttpResponse() {
    if (http.readyState == 4) {
        if (http.status == 200) {
            var timeValue = http.responseXML.getElementsByTagName("timenow")[0];
            alert(timeValue);
            document.getElementById('showtime').innerHTML = timeValue.childNodes[0].nodeValue;
        }
    }
}
</script>
</head>
<body style="background-color:#cccccc"
 onLoad="getServerTime()">
<center>
<h1>Ajax Demonstration</h1>
<h2>Getting the server time without page refresh</h2>
<form>
<input type="button" value="Get Server Time"
 onClick="getServerTime()">
</form>
<div id="showtime" class="displaybox"></div>
</center>
</body>
</html>

可能会有很多事情,因为正如其他人所指出的,我们想知道你看到了什么。但有一种猜测是,您请求的url与html文件不在同一服务器上。也就是说,您所在的html页面应该位于该页面上

你期望发生什么?到底发生了什么?您可以包含PHP代码吗?我们可以看到PHP脚本telltimeXML.PHP吗?请验证响应是否确实包含预期的XML,以及是否收到了响应。@alex:这是telltimeXML.PHP的代码,我已经尝试过让var/www文件夹中的文件ie this file和html页面客户端通过发送http来访问服务器端的内容ie timerequest@kevingessner:实际上,我想通过http请求和我发布的代码获取服务器时间…我在div框中..应该通过单击按钮来显示时间..@geon:我们怎么能检查响应是否包含预期的xml如果您只是在浏览器中输入url而不是使用javascript/xmlhttprequest,是否有效?返回的是什么?是的,我在浏览器中键入的时间显示在屏幕上
<?php header('Content-Type: text/xml'); echo "<?xml version=\"1.0\" ?><clock1><timenow>" .date('H:i:s')."</timenow></clock1>"; ?>