<html>
<head>
<title>test</title>
</head>
<body>
<script type='text/javascript'>
function createXMLHttpRequest(){
var xmlHttpRequest = null; //XMLHttpRequest Object
if (window.XMLHttpRequest) {
xmlHttpRequest = new XMLHttpRequest();
}
else
if (window.ActiveXObject) {
xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer 5.5+
}
else {
return false;
}
return xmlHttpRequest;
}
function postRequest(url, parameters){
var xmlHttpRequest;
xmlHttpRequest = createXMLHttpRequest();
if (!xmlHttpRequest) {
alert('Cannot create XMLHTTPRequest instance');
return false;
}
xmlHttpRequest.onreadystatechange = responseResult(xmlHttpRequest);
xmlHttpRequest.open('POST', url); // varAsync[optional] default is : true
xmlHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttpRequest.setRequestHeader("Content-length", parameters.length);
//http_request.setRequestHeader("Connection", "close");
xmlHttpRequest.send(parameters);
}
function responseResult(xmlHttpRequest){
var result;
if (xmlHttpRequest.readyState == 4) {
if (xmlHttpRequest.status == 200) { // 200 == OK
result = xmlHttpRequest.responseText;
}
else {
alert('There was a problem with the request.');
}
}
}
//postRequest('http://www.baidu.com', '');
</script>
</body>
</html>