查看单个帖子
旧 2005-10-20   #5
mudy
中级会员
级别:5 | 在线时长:98小时 | 升级还需:7小时级别:5 | 在线时长:98小时 | 升级还需:7小时
 
mudy 的头像
 
注册: 04年10月11日
帖子: 209
声望力: 24
声望: 10 mudy 闻道则喜
精华:3
现金:114两梁山币
资产:734两梁山币
致谢数: 0
获感谢文章数:0
获会员感谢数:0
回复: 那个flash的vote比较过时

那个vote就用了这点code,不过没有说用什么license。
Javascript部分,
代码:
function getHTML(divId,url)
{
	var method='GET';var data;
	var process=executeHTML;
	var async;
	var dosend;
	return new AJAXRequest(method,url,data,process,async,dosend,divId);
}

function executeHTML(AJAX,divId)
{
	if(AJAX.readyState==4){
		if(AJAX.status==200){document.getElementById(divId).innerHTML=AJAX.responseText;}
	}
}

var _ms_XMLHttpRequest_ActiveX="";

function AJAXRequest(method,url,data,process,async,dosend,extraObj)
{
	var self=this;
	if(window.XMLHttpRequest){self.AJAX=new XMLHttpRequest();}
	else if(window.ActiveXObject){
		if(_ms_XMLHttpRequest_ActiveX){self.AJAX=new ActiveXObject(_ms_XMLHttpRequest_ActiveX);}
		else {
			var versions=["Msxml2.XMLHTTP.7.0","Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
			for(var i=0;i<versions.length;i++){
				try{
					self.AJAX=new ActiveXObject(versions[i]);
					if(self.AJAX){_ms_XMLHttpRequest_ActiveX=versions[i];break;}
				}
				catch(objException){};
			};
		}
	}
	if(typeof process=='undefined'||process==null){process=executeReturn;}		self.process=process;self.AJAX.onreadystatechange=function(){self.process(self.AJAX,extraObj);}
	if(!method){method="POST";}
	method=method.toUpperCase();
	if(typeof async=='undefined'||async==null){async=true;}
	self.AJAX.open(method,url,async);
	if(method=="POST"){self.AJAX.setRequestHeader("Connection","close");
	self.AJAX.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	self.AJAX.setRequestHeader("Method","POST"+url+"HTTP/1.1");}
	if(dosend||typeof dosend=='undefined'){self.AJAX.send(data);}
	return self.AJAX;
}
HTML部分,
代码:
<div id="div_2005-08-08-bestfeature" class="poll">
<form id="form_2005-08-08-bestfeature" name="form_2005-08-08-bestfeature">
<h3>Mike Industries Poll</h3>
<p class="question">What is your favorite feature to be added to Mike Industries in the last year?</p>

<table><tr valign="top">
	<td><input type="radio" name="pollAnswer" id="0" value="0" /></td>
	<td><label for="0">The sIFR headlines.</label></td>
</tr><tr valign="top">
	<td><input type="radio" name="pollAnswer" id="1" value="1" /></td>
	<td><label for="1">The readability tools.</label></td>
</tr><tr valign="top">
	<td><input type="radio" name="pollAnswer" id="2" value="2" /></td>
	<td><label for="2">The Puget Sound Live Cam.</label></td>

</tr><tr valign="top">
	<td><input type="radio" name="pollAnswer" id="3" value="3" /></td>
	<td><label for="3">The Mike Industries mobile version.</label></td>
</tr><tr valign="top">
	<td><input type="radio" name="pollAnswer" id="4" value="4" /></td>
	<td><label for="4">The CSS Style Switcher.</label></td>
</tr><tr valign="top">
	<td><input type="radio" name="pollAnswer" id="5" value="5" /></td>
	<td><label for="5">This here fancy Ajax polling system.</label></td>

</tr></table>
<input type="button" value="VOTE" onclick="voteInPoll('2005-08-08-bestfeature', 'You did not place a vote.');" />
</form>
</div>

<script language="javascript" type="text/javascript">
function voteInPoll(pollName, errorMsg) {
	var yourVote;
	pollForm = document.getElementById('form_'+pollName);
	for(i=0; i < pollForm.elements.length; i++) {
		if(pollForm.elements[i].checked) yourVote = pollForm.elements[i].value;
	}
	if(!yourVote) alert(errorMsg);
	else ajaxResult = getHTML('div_'+pollName, '/blog/voting/vote.php?poll='+pollName+'&vote='+yourVote);
}
</script>
那个vote.php直接返回一个显示vote结果的html就可以了。

此帖于 2005-10-20 23:46 被 mudy 编辑.
mudy 当前离线  
回复时引用此帖