dqnf28092 2016-03-23 06:06
浏览 83

使用javascript按钮点击更改php状态的Ajax

I am trying to display 9 last uploaded images through AJAX, but also be able to navigate through past uploaded images as well.

 <script language = "javascript" type = "text/javascript">
              var x = 0;
             var xmlhttp = new XMLHttpRequest();
            xmlhttp.onreadystatechange = function() {
            nextButton.onclick = function(){
                  x+=1;
                      };

         document.getElementById("tst").innerHTML =         xmlhttp.responseText;

    };

           xmlhttp.open("GET", "getImage.php?=" + x , true);
           xmlhttp.send();

      </script>

             #getImage.php file
                 <?php 
                  $q = $_REQUEST["q"];
                  $req = intval($q);
                  echo $req;
                  ?>

I need $req to update every time the button is pressed but also be 0 when the page is loaded so it does not only display the images when the button pressed but also when the page has just loaded Thanks

  • 写回答

2条回答 默认 最新

  • dougehe2022 2016-03-23 06:26
    关注
    xmlhttp.open("GET", "getImage.php?=" + x , true);
    

    is wrong as there is no query parameter q replace it with

    xmlhttp.open("GET", "getImage.php?q=" + x , true);
    

    hope it helps :)

    评论

报告相同问题?

悬赏问题

  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)