在选定的div中显示我的结果

时间:2012-05-22 10:55:10

标签: php jquery

我有这样的表格:

<FORM id="frmVote" action="../vote_dir/proccess.php" method="post">
     <table id="tblMain" align="center">
        <tr>
        <td class="header"></td>
        </tr>
    <tr>
        <td>
             <?php
            include "../vote_dir/loadpoll.php";
             ?>
        </td>
    </tr>
    <tr>
        <td>
             <input id="votefor" name="votefor" type="hidden"/>
        </td>
    </tr>
    <tr>
        <td class="button">
             <INPUT class="btnVote" onclick="return confirmSubmit()" type="submit" value="vote"/>
        </td>
    </tr>
    <tr>
        <td class="footer"></td>
        </tr>
     </table>
</FORM>

这是proccess.php的一部分:

<?php
  $votefor = $_POST["votefor"];

  //Get the IP of the user
  $domain = $_SERVER["REMOTE_ADDR"];
  $today = date("m/d/Y");

  echo "<table id=\"tblResults\" align=\"center\">";

  //MORE CODE

// Generate the results table
  $doc = new DOMDocument();
  $doc->load("../vote_dir/xml/results.xml");
  $pollitems = $doc->getElementsByTagName("pollitem");
  foreach( $pollitems as $pollitem )
  {
    $entries = $pollitem->getElementsByTagName("entryname");
    $entry = $entries->item(0)->nodeValue;
    $votes = $pollitem->getElementsByTagName("votes");
    $vote = $votes->item(0)->nodeValue;
    $tempWidth = $vote / $maxvotes;
    $tempWidth = 300 * $tempWidth;
    $votepct = round(($vote / $maxvotes) * 100);
    echo "<tr><td width=\"45%\" class=\"polls\">$entry</td>";
    echo "<td width=\"35%\" class=\"resultbar\"><div class=\"bar\" style=\"background-color: ";
        getRandomColor();
        echo "; width: $tempWidth px;\">$votepct%</div></td><td class=\"each_vote\" width=\"20%\">($vote votes)</td></tr>";
  }
  echo "<tr><td width=\"45%\" class=\"total\" colspan=\"3\">Σύνολο ψήφων: $maxvotes</td>";
  echo "</table>";
?>

就像它现在一样正常。但我试图让它在特定的div中加载我的结果,而不是像

那样打开结果

我正在尝试使用这个jquery(我在其他东西中使用过),它正在部分工作,因为它在div中打开结果但似乎它没有将表单发送到proccess.php,因为我可以看到结果页面没有任何更改或消息,例如“您已经投票”。

  .delegate('.btnVote', 'click', function(){
     var keyValues = {
      votefor : $(this).parent().find('input[name="votefor"]').val()
     };
     $.post('../vote_dir/proccess.php', keyValues, function(rsp){
      $('#voting').load('../vote_dir/results.php');
     });
     return false;
  })

这是我的loadpoll.php

<?php 
  // Load the results xml file
  $doc = new DOMDocument();
  $doc->load("../vote_dir/xml/results.xml");
  $root = $doc->getElementsByTagName("results")->item(0);
  $question = $root->getAttribute("question");
  echo "<table id=\"tblPoll\" align=\"center\"><tr><td class=\"question\">$question</td></tr>";
  echo "<tr><td class=\"pollitem\">";
  $pollitems = $doc->getElementsByTagName("pollitem");
  $id = 1;
  // Loop through each item, and create a radio button for each item
  foreach( $pollitems as $pollitem )
  {
    $entries = $pollitem->getElementsByTagName("entryname");
    $entry = $entries->item(0)->nodeValue;
    $votes = $pollitem->getElementsByTagName("votes");
    $vote = $votes->item(0)->nodeValue;
    if ($id==1)
        echo "<input id=\"entry$id\" class=\"radiobutton\" onclick=\"setVote('$entry')\" type=\"radio\" name=\"poll\" value=\"$entry\">$entry<br>";
    else
        echo "<input id=\"entry$id\" onclick=\"setVote('$entry')\" type=\"radio\" name=\"poll\" value=\"$entry\">$entry<br>";
    $id = $id + 1;
  }
  echo "</td></tr>";
  echo "</table>";
?>

3 个答案:

答案 0 :(得分:0)

尝试更改

$(this).parent().find('input[name="votefor"]').val()

$('#votefor').val()

我认为“$(this).parent()”会导致<td>

答案 1 :(得分:0)

试试这个:

var data = $(this).parent().find('input[name= votefor]').val();

$data = $(this).parent().find('input[name= votefor]').val();

答案 2 :(得分:0)

  $('.btnVote').live('click', function () {
                $.post('../vote_dir/savevote.php', { votefor: $.trim($(this).parents('form').find('input[name="votefor"]').val()) }, function (data) {
                    $('#voting').html(data);

                    //Or

                    //$('#voting').load('../vote_dir/results.php');
                });

                return false;
            });
相关问题