我使用單選按鈕(用於輪詢)製作了一個表單。
而我使用$.ajax
來提交表單。
但是當我使用$("#polling").serialize()
作爲數據時,沒有任何發送/請求...
單選按鈕有問題嗎?
$(function(){ $("input[name=vote]").click(function(){
var id_polling = $("input[name=id_polling]");
$("div[class=poll-content]").text("Loading");
$.ajax({
type: "POST",
url: BASE_URL + "/processes/polling.php",
data: $("#polling").serialize(),
success: function(msg){
document.getElementById("poll-content").innerHTML = msg;
}
});
});
,這是HTML代碼:
<div class="poll-content" id="poll-content">
<form action="#" id="polling">
<?php
$poll = Polling::_find_by_id($id);
$view = "<h4 class=\"polling\">" . $poll->nama . "</h4>";
$options = explode(",", $poll->opsi);
foreach ($options as $i => $option) {
$view .= "<input type=\"radio\" class=\"option\" name=\"option\" value=\"" . $option . "\" />";
$view .= $option;
$view .= "<br />";
}
$view .= "<input type=\"hidden\" name=\"id_polling\" value=\"" . $poll->id_polling . "\">";
echo $view;
?>
<input type="button" name="vote" value="Vote" />
</form>
</div>
可以請你發佈完整的代碼? – sanders 2011-04-24 14:31:26
請使用新代碼編輯您的文章。 – 2011-04-24 14:43:04
將代碼從評論移動到問題 – 2011-04-24 14:47:55