<%@page language="java" contentType="text/html;charset=gb2312"%>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<jsp:useBean id="dbquery" class="Back.DBQuery" scope="page" />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<script type="text/javascript">
var xmlHttp;
/**
*创建XMLHttpRequest对象,此对象是AJAX核心,用于发送异步请求
*
*/
function createXMLHttpRequest(){
if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}else if (window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
/**
*生成xml字符串
*
*/
function createXML(){
var xml = "<pubrequest>";
xml += "<pid>2011091615430101</pid>";
xml += "<methodid>1201</methodid>";
xml += "<methodparameter>";
xml += "<dsqh>0551</dsqh>";
xml += "<khh>5100474397</khh>";
//xml += "<khh>5130804375</khh>";
xml += "</methodparameter>";
xml += "</pubrequest>";
return xml;
}
function getTimetamp()
{
var d = new Date();
var h = d.getHours();
if(h.length == 0)
h = "0" + h;
var xx = d.getFullYear()+""+(d.getMonth()+1).lenght>1?(d.getMonth()+1):"0"+(d.getMonth()+1)+""+d.getDate()+""+d.getHours()+""+d.getMinutes()+""+d.getSeconds();
return xx + "01";
}
/**
*发送POST请求
*
*/
function sendPetTypes(){
createXMLHttpRequest();
var xml=createXML();
//我的项目叫Ajax1所以应该更改成你的项目名
//timeStamp=new Date().getTime()是用来生成一个时间戳用于防止url被缓存:因为每次new Date().getTime 方法都会生一个long的值,此值不会重复所以每次的url都是唯一的,所以就不可能去缓存中读数据了。
var url="http://221.130.165.214:58986/wxcs";
xmlHttp.open("POST",url,true);
xmlHttp.onreadystatechange = handleStateChange;
//Post请求所必须设置的请求头信息
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send(xml);
}
function handleStateChange(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
//成功返回后调用此方法
alert(xmlHttp.responseText);
}
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body leftmargin="0" topmargin="0">
<input type="button" value="执行" onclick="sendPetTypes();">
<input type="button" value="时间戳" onclick="alert(getTimetamp());">
</body>
</html>