0

我有这个表格:

<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>";
?>
4

3 回答 3

0

尝试更改

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

$('#votefor').val()

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

于 2012-05-22T11:07:06.460 回答
0

试试这个:

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

或者

$data = $(this).parent().find('input[name= votefor]').val();
于 2012-05-22T11:14:05.910 回答
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;
            });
于 2012-05-22T11:22:50.460 回答