dongyan7876 2014-04-26 07:07
浏览 53
已采纳

AJAX中的jQuery没有更新

I have a webpage - lets call it index.php. Using AJAX I load content from another page after a dropdown selection - lets call this one catalog.php.

catalog.php has an empty DIV, that, using jQuery, gets some text from yet another page - this final one will be called data.php. It replaces the contents of the DIV, and refreshes every 1 second.

If I go directly to catalog.php (using the proper GET), the jQuery will run and the DIV will update every second as needed.

However, if I go to index.php - catalog.php will load and run, but the DIV remains empty, and it will not populate the DIV with data.php.

What's going on here?

Sample code from index.php:

<script>
    function showForm(str) {
      if (str=="") {
        document.getElementById("txtHint").innerHTML="";
        return;
      } 
      if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
      } else { // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
          document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
      }
      xmlhttp.open("GET","catalog.php?q="+str,true);
      xmlhttp.send();
    }
</script>

Sample code from catalog.php:

<div id="divstuff"></div>
<script src="jq.js"></script>
<script type="text/javascript">
window.setInterval(function(){
            $("#divstuff").load("data.php?data=somedata");
}, 1000);</script>

It's all echo'd via PHP and such. data.php just has some basic stuff printed with PHP.

  • 写回答

1条回答 默认 最新

  • duanbei6427 2014-04-26 07:21
    关注

    Best practice would be to load paid.php on index.php. Just move your setInterval code and add the DIV with id = "payment" to index.php.

    If you want to keep it how it is now, you need to make sure the JS that is returned from cart.php is actually running. Also make sure you only have one DIV with id = "payment".

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

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP