首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

xmlHttp跟ajaxrequest

2013-01-21 
xmlHttp和ajaxrequest//ajax后台?public String checkData() {??try {???HttpServletRequest request Se

xmlHttp和ajaxrequest

//ajax后台
?public String checkData() {
??try {
???HttpServletRequest request = ServletActionContext.getRequest();
???HttpServletResponse response=ServletActionContext.getResponse();
???PrintWriter writer = response.getWriter();
???String editId=request.getParameter("editId");
???String startTime=request.getParameter("start_time");
???String endTime=request.getParameter("end_time");
???boolean flag=false;
//???flag=sendPlanMgr.checkByCallType(editId,startTime, endTime);
???if (flag)
????writer.write("fail");
????? else {
????? ?writer.write("success");
????? }
????? writer.flush();
????? writer.close();
??} catch (Exception e) {
//???log.error(e.getMessage());
???e.printStackTrace();
??}
??return null;
?}

********************************************************************

<script type="text/javascript">
/**
?* 得到ajax对象
?*/
function getajaxHttp() {
?var xmlHttp;
?try {
??// Firefox, Opera 8.0+, Safari
??xmlHttp = new XMLHttpRequest();
??} catch (e) {
???// Internet Explorer
???try {
????xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
???} catch (e) {
???try {
????xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
???} catch (e) {
????alert("您的浏览器不支持AJAX!");
????return false;
???}
??}
?}
?return xmlHttp;
}

/**
?* 发送ajax请求
?* url--url
?* methodtype(post/get)
?* con (true(异步)|false(同步))
?* functionName(回调方法名,不需要引号,这里只有成功的时候才调用)
?* (注意:这方法有二个参数,一个就是xmlhttp,一个就是要处理的对象)
?* obj需要到回调方法中处理的对象
?*/
function ajaxrequest(url,methodtype,con,functionName,obj){
?var xmlhttp=getajaxHttp();
?xmlhttp.onreadystatechange=function(){
??if (xmlhttp.readyState==4){
???? if (xmlhttp.status==200){
????? functionName(xmlhttp.responseText);
????? }
??? }
??
?};
?xmlhttp.open(methodtype,url,con);
?xmlhttp.send();
}
function onSuccess(response){
?if(response=="fail"){
??alert("时间段已存在,请更改其他时间段");
??return false;
?}else{
??$("msgStraForm").submit();
?}
}
function checkSub(){
?var send_content=document.getElementById("send_content").value;
?var start_time=document.getElementById("start_time").value;
?var end_time=document.getElementById("end_time").value;
?var msgStraBtnSub=document.getElementById("msgStraBtnSub").value;
?var url;
?var editMsgsid;
?editMsgsid=document.getElementById("EditMsgsid").value;
?if(send_content==""){
??alert("请输入内容");
??return false;
?}if(send_content.length>195){
??alert("发送内容不能超过195个汉字");
??return false;
?}
?if(parseInt(start_time)>parseInt(end_time)||parseInt(end_time)==parseInt(start_time)){
??alert("时间段选择错误,请重新选择");
??return false;
?}
?var url="./strategy!checkData?editId="+editMsgsid+"&start_time="+start_time+"&end_time="+end_time;
?ajaxrequest(url,"post",true,onSuccess,document);
}
</script>

热点排行