<!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>
<title>send string</title>
<script language=javascript>
var xmlhttp;
function createxmlhttprequest()
{
if(window.ActiveXObject)
{
xmlhttp=new ActiveXObject((navigator.userAgent.toLowerCase().indexOf('msie 5') != -1) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP');
}
}
function sendstring()
{
for(var i=0;i<2;i++)
{
createxmlhttprequest();
xmlhttp.onreadystatechange=statechange;
xmlhttp.open('POST','ajax.aspx',false);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(getFormQueryString("ff"));
}
}
function statechange()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("x").innerHTML=xmlhttp.responseText;
}
}
function Button1_onclick() {
sendstring();
}
//得到一个表单里的全部信息
function getFormQueryString(frmID)
{
var frmID=document.getElementById(frmID);
var i,queryString = "", and = "";
var item; // for each form's object
var itemValue;// store each form object's value
for( i=0;i<frmID.length;i++ )
{
item = frmID[i];// get form's each object
if ( item.name!='' )
{
if ( item.type == 'select-one' )
{
itemValue = item.options[item.selectedIndex].value;
}
else if ( item.type=='checkbox' || item.type=='radio')
{
if ( item.checked == false )
{
continue;
}
itemValue = item.value;
}
else if ( item.type == 'button' || item.type == 'submit' || item.type == 'reset' || item.type == 'image')
{// ignore this type
continue;
}
else
{
itemValue = item.value;
}
itemValue = encodeURIComponent(itemValue);
queryString += and + item.name + '=' + itemValue;
and="&";
}
}
return queryString;
}
</script>
</head>
<body >
<form id=ff name=ff>
<input type=text id="tbx" name="tbx" />
<input id="Button1" type="button" value="button" language="javascript" onclick="return Button1_onclick()" /><br />
<br />
<br />
<div id=x></div>
asdf<input id="Checkbox1" name="weew" type="checkbox" />
<input id="Radio1" name="sdfsdf" type="radio" />
<input id="Radio2" checked="checked" name="fff" type="radio" />
<textarea id="TextArea1" cols="20" name="wr2234" rows="2"></textarea>
<select id="Select1" name="fff">
<option selected="selected" value="1">dsf</option>
<option value="2">214312</option>
<option value="3">23421</option>
</select>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>send string</title>
<script language=javascript>
var xmlhttp;
function createxmlhttprequest()
{
if(window.ActiveXObject)
{
xmlhttp=new ActiveXObject((navigator.userAgent.toLowerCase().indexOf('msie 5') != -1) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP');
}
}
function sendstring()
{
for(var i=0;i<2;i++)
{
createxmlhttprequest();
xmlhttp.onreadystatechange=statechange;
xmlhttp.open('POST','ajax.aspx',false);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(getFormQueryString("ff"));
}
}
function statechange()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("x").innerHTML=xmlhttp.responseText;
}
}
function Button1_onclick() {
sendstring();
}
//得到一个表单里的全部信息
function getFormQueryString(frmID)
{
var frmID=document.getElementById(frmID);
var i,queryString = "", and = "";
var item; // for each form's object
var itemValue;// store each form object's value
for( i=0;i<frmID.length;i++ )
{
item = frmID[i];// get form's each object
if ( item.name!='' )
{
if ( item.type == 'select-one' )
{
itemValue = item.options[item.selectedIndex].value;
}
else if ( item.type=='checkbox' || item.type=='radio')
{
if ( item.checked == false )
{
continue;
}
itemValue = item.value;
}
else if ( item.type == 'button' || item.type == 'submit' || item.type == 'reset' || item.type == 'image')
{// ignore this type
continue;
}
else
{
itemValue = item.value;
}
itemValue = encodeURIComponent(itemValue);
queryString += and + item.name + '=' + itemValue;
and="&";
}
}
return queryString;
}
</script>
</head>
<body >
<form id=ff name=ff>
<input type=text id="tbx" name="tbx" />
<input id="Button1" type="button" value="button" language="javascript" onclick="return Button1_onclick()" /><br />
<br />
<br />
<div id=x></div>
asdf<input id="Checkbox1" name="weew" type="checkbox" />
<input id="Radio1" name="sdfsdf" type="radio" />
<input id="Radio2" checked="checked" name="fff" type="radio" />
<textarea id="TextArea1" cols="20" name="wr2234" rows="2"></textarea>
<select id="Select1" name="fff">
<option selected="selected" value="1">dsf</option>
<option value="2">214312</option>
<option value="3">23421</option>
</select>
</form>
</body>
</html>