在HTML页面中播放更新的值

时间:2012-01-16 22:03:46

标签: php jquery ajax

我正在尝试使用AJAX使我的网站比现在更流畅。

我有一段显示以下内容的代码

if($guess == 0){
  echo "Enter a guess:;
  *AJAX form* ---> inserts a MySQL database record with the users guess
  <div to show results of script for form> - not necessarily needed
  }else{
  echo "Update your guess:";
  *SAME AJAX form* ---> updates the MySQL database record with the users new guess
  <div to show results of script for form> - - not necessarily needed
}

我遇到的问题是我想要显示网页的一部分:

您的最新猜测是:£x.xx

然而,因为用户将以0猜测开始,并且AJAX发送表格“幕后”,我很难知道如果用户猜测后如何显示上述行。

因此,当他们稍后重新访问该页面时,它会显示他们最后的猜测。

这是我希望能够刷新的页面中唯一的2个元素,其余信息不必刷新。

这里有更多代码:

<?php
              if($guessess_open == 1){
                      echo "<h2>guesses are CLOSED</h2>";
              }
              else{   

                //it's this part that I want to have always shown on the page, but when I visit the page fresh it doesn't show me any results.  

                <div id="results"></div>



                <form name="myform" id="myform" action="" method="POST">  
                <!-- The all important guess field -->
                <label for="guess" id="guess_label">Guess<br></label>  
                <input type="text" name="guess" id="guess" size="10" value=""/> 
                <?php
                echo "<input type='hidden' name='user_id' id='user_id' size='10' value='$user'/>";
                echo "<input type='hidden' name='item_id' id='item_id' size='10' value='$itemID'/>";
                echo "<input type='hidden' name='title' id='title' size='100' value='$title2'/>";
                echo "<input type='hidden' name='owner_id' id='owner_id' size='10' value='$ownerid'/>";
                echo "<input type='hidden' name='guesses_open' id='guesses_open' size='10' value='$guesses_open'/>";
                echo "<input type='hidden' name='exist' id='exist' size='10' value='$exist'/>";
                ?>
                <!-- The Submit button -->
                <br>
                <input type="image" name="submit" src="URL" width="150px" height="100px">
                </form>

我可以让它在页面的这一部分显示某些内容的唯一方法是使用一些代码来检查数据库的猜测,如果它存在则显示结果,但是当我提交新表单时,因为它只更新它不会更新代码部分的结果,例如可以包括

else{     
        include("URL.php?item_id=" . $itemID. "&user=" .$user. "");?>               
        //it's this part that I want to have always shown on the page, but when I visit the page fresh it doesn't show me any results.  
      <div id="results"></div>

显示用户访问该页面时的最新猜测,但是当进行新的猜测时,这不会更新...我不必让我的表单php up显示结果如果上面的部分每次我猜测时代码都会更新...我希望这更清楚?

0 个答案:

没有答案