duanjia9577 2014-12-11 14:35
浏览 65
已采纳

Ajax发布到PHP并获取返回数据

I am developing a slider to set my budget and would like to achieve the value which I set in slider1.php. However, when I tried using the code below, I encountered an error "Notice: Undefined index: slideStatus in C:\xampp\htdocs\1204763e\slider1\slider1.php on line 4 Thank you , says the PHP file"

In slide.php, I inserted this set of code:

     <html>
    <head>
    <script language="JavaScript" type="text/javascript">

    function ajax_post(val){

        var hr = new XMLHttpRequest();

        var url = "slider1.php";
        var ss = document.getElementById('sliderStatus').innerHTML = val;
        var vars = "sliderStatus="+ss;
        hr.open("POST", url, true);

        hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

        hr.onreadystatechange = function() {
            if(hr.readyState == 4 && hr.status == 200) {
                var return_data = hr.responseText;
                document.getElementById("status").innerHTML = return_data;
            }
        }
        // Send the data to PHP now... and wait for response to update the status div
        hr.send(vars); // Actually execute the request
        document.getElementById("status").innerHTML = "processing...";
    }
    </script>
    </head>
    <body>
    <h2>Ajax Post to PHP and Get Return Data</h2>

    <input type="range" name="slide" min="0" max="100" value="50" step="2" onChange="ajax_post(this.value)" />
    <br /><br />
    <span id="sliderStatus">50</span>
    <br/><br/>

    <div id="status"></div>

    </body>
    </html>



In slider1.php, I inserted this set of code:

    <?php 
    echo 'Thank you '. $_GET['slideStatus'] . ', says the PHP file';
    ?>
  • 写回答

1条回答 默认 最新

  • dongzipu7517 2014-12-11 14:40
    关注

    You seem to try to access "slideStatus" but you are posting "sliderStatus".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了