Why this random number changes twice while posting form?

Discussion in 'JavaScript' started by buk, Aug 4, 2011.

  1. #1
    Hello,
    There isa demo below.
    I have a form and select menus. I am posting it ajax post method and loading the same page with load method as you see in codes. There is a random number genarator. I want to change this random number once a click submit. If i do not load the same page this number does not change. Therefore I use both post and load methods like in demo. However when i do like this there is a problem which is random number have been generated twice somtimes. If you click submit button successively you will see that the number on left top corner sometimes changes twice a click. Why it is so and how can i correct it.
    Thanks in advance and sorry for my bad English:eek:

    Demo:
    http://fcbk.imeee.org/test.php

    test.php
    <?php
    print_r($_POST['soru']);
    echo rand(5, 15);
    
    ?> 
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <link href="style.css" media="screen" rel="Stylesheet" type="text/css">
    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function()
    {
     $("#submit").click(function(event){
              $.post( 
                 "test.php",
                 $("#sorular").serializeArray(),
                     function(data) {
                    $('#results').html(data);
                 }
              );
              $(".arkadaslar").load("test.php?r=1"); 
          });
    
    });    
    
    </script> 
    </head>
    
    <body>
    <?php if(!$_POST):?>
    <?php if($_GET['r']!=1):?>
       <ul class="arkadaslar">
    <?php endif;?>   
            <form name="ss" id="sorular">
            <?php for($i = 1; $i <= 4; $i++):?>
                   <table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
                      <tr>
                        <td width="70%" align="left" valign="top"></td>
                        <td width="30%" align="left" valign="top">
                        
                          <label>
                          <select name="soru[]" size="1" id="select">
                            <option>Give point</option>
                            <option value="1">1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                            <option value="4">4</option>
                            <option value="5">5</option>
                            <option value="6">6</option>
                            <option value="7">7</option>
                            <option value="8">8</option>
                            <option value="9">9</option>
                            <option value="10">10</option>
                          </select>
                          </label>
                        </td>
                      </tr>
                      
                    </table><br /><br /> 
                   <?php endfor; ?>   
                   <input id="submit" type="button" value="Submit"> 
                   </form>
    
    </ul>
    <?php endif;?>
        <p><tt id="results">
        
       
        </tt></p>
        
    
    
    </body>
    </html>
    
    PHP:
     
    buk, Aug 4, 2011 IP
  2. prasanthmj

    prasanthmj Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    45
    #2
    There are two calls: post and load. only one is required.
    Use firebug. Go to the console tab in firebug. see the responses from each of the calls
     
    prasanthmj, Aug 4, 2011 IP