XMLHTTPRequest URLEncoding

記錄一下,免得每次都腦包忘了怎麼做...

<script>
var sendMsg = new XMLHttpRequest();

function sendMessage(_vU, _vR, txtMsgEle, _iframe)
{
	sendMsg.onreadystatechange = function()
		{
			loadMessages(document.form1.listUser.value, document.form1.listCR.value);
		};
	sendMsg.open( "GET", "http://URI?msg=" + encodeURIComponent(txtMsgEle.value), true );
	sendMsg.send("");
	txtMsgEle.value = "";
}
</script>
<body onload="javascript:init();">
	<form name="form1" onsubmit="javascript:return false;">
		<select name="listUser" size="5" onchange="javascript:loadChatroom();"></select>
		<select name="listCR" size="5" onchange="javascript:loadMessages(document.form1.listUser.value, document.form1.listCR.value);"></select>
		<iframe name="listMsg" width="600" height="300" src="msg.html"></iframe>
		<input type="text" name="msg" size="50">
		<input type="button" value="send" onclick="javascript:sendMessage(document.form1.listUser.value, document.form1.listCR.value, document.form1.msg, frames[0]);">
	</form>
</body>