Javascript php没有接收从xmlhttprequest发送的数据?
这个网站真的只是为了娱乐。但是当我点击按钮时,ajax发送的发布数据没有收到。它不起作用Javascript php没有接收从xmlhttprequest发送的数据?,javascript,php,html,ajax,xmlhttprequest,Javascript,Php,Html,Ajax,Xmlhttprequest,这个网站真的只是为了娱乐。但是当我点击按钮时,ajax发送的发布数据没有收到。它不起作用 <?php $recieved = $_POST["started"]; if ($recieved == "TRUE") { echo 'pinging: ' . $_SERVER["REMOTE_ADDR"]; sleep(.2); echo 'pinging local k3wlk1d servers'; sleep
<?php
$recieved = $_POST["started"];
if ($recieved == "TRUE") {
echo 'pinging: ' . $_SERVER["REMOTE_ADDR"];
sleep(.2);
echo 'pinging local k3wlk1d servers';
sleep(.2);
echo 'executing terminal...';
sleep(.2);
echo 'cmd.execute:: settime 01012014';
sleep(.2);
echo 'cmd.execute:: ping 127.0.0.1';
sleep(.2);
echo 'cmd.execute:: getfiles(k3wlk1d.server, 127.0.0.1, xmlhttprequest=true)';
sleep(.2);
echo 'secure connection established';
sleep(.2);
echo 'sending to old kewlkids site...';
}
?>
<!DOCTYPE html>
<link rel="stylesheet" href="timemachine.css">
<html lang="en">
<head>
<meta charset="utf-8" />
<title>K3WLK1DZ TIME MACHINE</title>
</head>
<body>
<font color="red">This is an experimental time machine that will send you back to the old k3wlk1dz page. Press the button to continue.</font>
<button class="btn" onclick="ajaxstart()">Start</button>
<p id="return"></p>
<script>
function ajaxstart() { /*
wait
WAIT
why am i using ajax
oh wait
i need to contact the server for... something. I forgot.
Darn.
ok
*/
var xmlhttp;
if (window.XMLHttpRequest) {
//for ie 7, firefox, chrome, opera, safari, and *POSSIBLY* microsoft edge
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHttp");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
/* english translation: if http request is successful, run this block of code*/
var ret = document.getElementById("return");
ret.innerHTML = xmlhttp.responseText;
}
xmlhttp.open("POST", "timemachine.php", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("started=TRUE");
}
}
</script>
</body>
</html>
K3WLK1DZ时间机器
这是一个实验性的时间机器,它将把你送回旧的k3wlk1dz页面。按下按钮继续。
开始
函数ajaxstart(){/*
等待
等待
为什么我要使用ajax
哦,等等
我需要和服务器联系……我忘了。
该死。
好啊
*/
var-xmlhttp;
if(window.XMLHttpRequest){
//适用于IE7、firefox、chrome、opera、safari和微软edge
xmlhttp=新的XMLHttpRequest();
}否则{
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
/*如果http请求成功,请运行此代码块*/
var ret=document.getElementById(“返回”);
ret.innerHTML=xmlhttp.responseText;
}
open(“POST”,“timemachine.php”,true);
setRequestHeader(“内容类型”,“应用程序/x-www-form-urlencoded”);
send(“started=TRUE”);
}
}
尝试将xmlhttp.open/steRequestHeader/send方法置于onreadystatechange方法之外,如下所示:
<script>
function ajaxstart() { /*
wait
WAIT
why am i using ajax
oh wait
i need to contact the server for... something. I forgot.
Darn.
ok
*/
var xmlhttp;
if (window.XMLHttpRequest) {
//for ie 7, firefox, chrome, opera, safari, and *POSSIBLY* microsoft edge
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHttp");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
/* english translation: if http request is successful, run this block of code*/
var ret = document.getElementById("return");
ret.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("POST", "timemachine.php", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("started=TRUE");
}
</script>
函数ajaxstart(){/*
等待
等待
为什么我要使用ajax
哦,等等
我需要和服务器联系……我忘了。
该死。
好啊
*/
var-xmlhttp;
if(window.XMLHttpRequest){
//适用于IE7、firefox、chrome、opera、safari和微软edge
xmlhttp=新的XMLHttpRequest();
}否则{
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
/*如果http请求成功,请运行此代码块*/
var ret=document.getElementById(“返回”);
ret.innerHTML=xmlhttp.responseText;
}
}
open(“POST”,“timemachine.php”,true);
setRequestHeader(“内容类型”,“应用程序/x-www-form-urlencoded”);
send(“started=TRUE”);
}
onreadystatechange函数存在问题
试试下面的代码
<?php
$recieved = @$_POST["started"];
if ($recieved == "TRUE") {
echo 'pinging: ' . $_SERVER["REMOTE_ADDR"];
sleep(.2);
echo 'pinging local k3wlk1d servers';
sleep(.2);
echo 'executing terminal...';
sleep(.2);
echo 'cmd.execute:: settime 01012014';
sleep(.2);
echo 'cmd.execute:: ping 127.0.0.1';
sleep(.2);
echo 'cmd.execute:: getfiles(k3wlk1d.server, 127.0.0.1, xmlhttprequest=true)';
sleep(.2);
echo 'secure connection established';
sleep(.2);
echo 'sending to old kewlkids site...';
}
?>
<!DOCTYPE html>
<link rel="stylesheet" href="timemachine.css">
<html lang="en">
<head>
<meta charset="utf-8" />
<title>K3WLK1DZ TIME MACHINE</title>
</head>
<body>
<font color="red">This is an experimental time machine that will send you back to the old k3wlk1dz page. Press the button to continue.</font>
<button class="btn" onclick="ajaxstart()">Start</button>
<p id="return"></p>
<script>
function ajaxstart() { /*
wait
WAIT
why am i using ajax
oh wait
i need to contact the server for... something. I forgot.
Darn.
ok
*/
var xmlhttp;
if (window.XMLHttpRequest) {
//for ie 7, firefox, chrome, opera, safari, and *POSSIBLY* microsoft edge
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHttp");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
/* english translation: if http request is successful, run this block of code*/
var ret = document.getElementById("return");
ret.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("POST", "timemachine.php", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("started=TRUE");
}
</script>
</body>
</html>
K3WLK1DZ时间机器
这是一个实验性的时间机器,它将把你送回旧的k3wlk1dz页面。按下按钮继续。
开始
函数ajaxstart(){/*
等待
等待
为什么我要使用ajax
哦,等等
我需要和服务器联系……我忘了。
该死。
好啊
*/
var-xmlhttp;
if(window.XMLHttpRequest){
//适用于IE7、firefox、chrome、opera、safari和微软edge
xmlhttp=新的XMLHttpRequest();
}否则{
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
/*如果http请求成功,请运行此代码块*/
var ret=document.getElementById(“返回”);
ret.innerHTML=xmlhttp.responseText;
}
}
open(“POST”,“timemachine.php”,true);
setRequestHeader(“内容类型”,“应用程序/x-www-form-urlencoded”);
send(“started=TRUE”);
}
希望这会有所帮助
关于检查您的
onreadystatechange
功能。