2015-09-20 98 views
-1

这个网站真的只是为了娱乐。但是,当我点击按钮时,由ajax发送的发布数据没有收到。它不起作用。PHP没有收到xmlhttprequest发送的数据?

<?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> 
+0

检查你的'onreadystatechange'函数。 – ElefantPhace

回答

0

尝试采取xmlhttp.open/steRequestHeader/send方法outeside的方法的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> 
0

你有你的问题的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> 

希望这会有所帮助

Regards