dongyang7152 2015-09-20 05:05
浏览 72

php没有收到从xmlhttprequest发送的数据?

This website is really just for amusement. But the posted data sent by ajax isn't getting received as when I click the button. it doesn't work.

<?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>
  • 写回答

2条回答 默认 最新

  • dps43378 2015-09-20 06:08
    关注

    Try to take xmlhttp.open/steRequestHeader/send methods outeside the onreadystatechange method like this:

       <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>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示