<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function refreshModelList() {
var url = "ajaxpost.aspx"
var query="pid=11&toid=1395493964&content="+UrlEncode("測試");
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send(query);
}
function handleStateChange() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
updateModelsList();
}
}
}
function updateModelsList() {
var make = document.getElementById("make");
var results = xmlHttp.responseText;
make.innerHTML=results;
}
</script>
<title>ajaxpost test</title>
</head>
<body>
<div id="make"></div><br>
<input type="button" value="obtain info " onclick="refreshModelList()">
</body>
</html>
<script language="vbscript">
Function str2asc(strstr)
str2asc = hex(asc(strstr))
End Function
Function asc2str(ascasc)
asc2str = chr(ascasc)
End Function
</script>
<script language="javascript">
/*這裡開始時UrlEncode和UrlDecode函數*/
function UrlEncode(str){
var ret="";
var strSpecial="!\"#$%&'()*+,/:;<=>?[]^`{|}~%";
var tt= "";
for(var i=0;i<str.length;i++){
var chr = str.charAt(i);
var c=str2asc(chr);
tt += chr+":"+c+"n";
if(parseInt("0x"+c) > 0x7f){
ret+="%"+c.slice(0,2)+"%"+c.slice(-2);
}else{
if(chr==" ")
ret+="+";
else if(strSpecial.indexOf(chr)!=-1)
ret+="%"+c.toString(16);
else
ret+=chr;
}
}
return ret;
}
function UrlDecode(str){
var ret="";
for(var i=0;i<str.length;i++){
var chr = str.charAt(i);
if(chr == "+"){
ret+=" ";
}else if(chr=="%"){
var asc = str.substring(i+1,i+3);
if(parseInt("0x"+asc)>0x7f){
ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6)));
i+=5;
}else{
ret+=asc2str(parseInt("0x"+asc));
i+=2;
}
}else{
ret+= chr;
}
}
return ret;
}
</script>