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

Php 在选定的div中显示我的结果,php,jquery,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>

我有以下表格:

<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>
这是我的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>";
?>
load(“../vote_dir/xml/results.xml”);
$root=$doc->getElementsByTagName(“结果”)->项(0);
$QUOTE=$root->getAttribute(“问题”);
回应“$问题”;
回声“;
$pollitems=$doc->getElementsByTagName(“pollitem”);
$id=1;
//循环浏览每个项目,并为每个项目创建一个单选按钮
foreach($pollitems作为$pollitem)
{
$entries=$pollitem->getElementsByTagName(“entryname”);
$entry=$entries->item(0)->nodeValue;
$Voces=$pollitem->getElementsByTagName(“投票”);
$vote=$votes->item(0)->nodeValue;
如果($id==1)
回显“$entry
”; 其他的 回显“$entry
”; $id=$id+1; } 回声“; 回声“; ?>
尝试更改

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

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

尝试以下方法:

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


隐马尔可夫模型。。。或者它应该是
$(this).parent().parent().parent().find('input[name=votefor]').val()
..)在loadpoll.php中,它将包含属性id“#投票”。我没有看到任何属性id=“#voting”以及savevote.php将返回什么输出?它似乎可以工作,但在显示正确的数据后,它会立即重新加载result.php(然后它会获得默认消息…例如,它不会显示“you Haven Vote”,而是显示“voting results are”),其中您会检查“you Haven Vote”的条件在savevote.php post中(使用if-else条件)。因此,如果他已经投票,则回应“你已经投票”;否则呼应“投票结果”;我正在使用else语句。。。问题似乎是results.php加载了2ice。如果我只调用results.php,我将得到投票结果,但没有任何形式(如纯文本)。因此,使用您的脚本一毫秒后,我就得到了result.php,然后再次加载,生成纯文本格式和默认的msgs.post success$(“#voting”).load(“../vote_dir/results.php”);删除此行并使用$('#voting').html(数据);如上代码
$(this).parent().find('input[name="votefor"]').val()
$('#votefor').val()
var data = $(this).parent().find('input[name= votefor]').val();
$data = $(this).parent().find('input[name= votefor]').val();
  $('.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;
            });