显示投票结果的地方投票区 [英] Showing poll results in place of the poll area
问题描述
我想从展示在同一地区和页面的投票问题的一项民意调查结果无需重新加载整个页面。我能够得到的结果,并显示在一个新的页面,但我不知道如何来取代HTML在我有问题,它与结果的HTML替换。
I am trying to show the results from a poll in the same area and page as the poll question without reloading the entire page. I am able to get the results and show them in a new page but I do not know how to replace the html in where I have the question and replace it with the html with the results.
HTML (与投票问题)
<div id="poll-area">
<!-- Voting poll -->
<fieldset>
<form action="javascript:void(0);" id="pollid" name="myform" method="POST">
<label><input type="radio" name="answer" value="left" id="option_left" />Yes</label>
<label><input type="radio" name="answer" value="right" id="option_right" />No</label>
<input type="submit" name="submit" id="submit" value="Vote" />
<input type="hidden" name="id" value="pollid" />
</form>
</fieldset>
<!-- End voting poll -->
</div>
AJAX 呼叫处理的投票:
var $j = jQuery.noConflict();
jQuery(document).ready(function($j) {
$j("form").submit(function(){
var str = $j(this).serialize();
$j.ajax({
url: "poll_vote.php",
type: "POST",
data: str,
cache: false,
success: function(result) {
window.location.replace("poll_results.php");
}
});
return false;
});
});
我猜测这是不是* window.location.replace(poll_results.php)*我想要替换为#轮询区#调查区域内的HTML中poll_results.php,但我不知道该怎么做。
I am guessing it is instead of the *window.location.replace("poll_results.php")* that I want to replace the HTML within the #poll-area with the #poll-area in the poll_results.php, but I do not know how do it.
HTML 作为投票结果(什么是包含在poll_results.php)
HTML for the poll results (what is contained in poll_results.php)
<div id="poll-area">
<fieldset>
<legend>Results</legend>
<ul>
<li>
<span class="total-votes">Yes</span>
<br />
<div class="results-bar" style="width:52%;">
52%
</div>
</li>
<li>
<span class="total-votes">No</span>
<div class="results-bar right-bar" style="width:48%;">
48%
</div>
</li>
<li>
</ul>
<p>Total votes: 100</p>
</fieldset>
</div>
感谢您的帮助!
Thanks for the help!
推荐答案
在输出的 poll_results.php 可以去掉外层div id为调查区。你不想重复的ID,当它被拉到到当前页面。
in the output of poll_results.php you can remove the outer div with the id "poll-area". You don't want duplicate IDs when it is pulled into your current page.
有关您的jQuery,这应该做的伎俩:
For your jQuery, this should do the trick:
success: function(result) {
$j("#poll-area").html(result);
我所知,任何当前exiits投票区格内将覆盖从阿贾克斯查询结果。 (投票选项应该消失,其结果将显示)
As I'm aware, anything that currently exiits inside the poll-area div will be overwritten with the result from the ajax query. (The voting options should disappear, and the results will be shown)
编辑(评论摘要):的 poll_vote.php
应该输出包含在 poll_results.php 在HTML code>
这篇关于显示投票结果的地方投票区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!