ajax同步提交 晕死

时间:2022-12-24 13:33:21

xmlHttpRequest.open("POST", url, false); // 同步请求,true为异步
不就会等待你的ajax请求返回了吗?
 

 if(action.equalsIgnoreCase("get")){



        ArrayList arr_oaSchedule=(ArrayList)oaScheduleService.findByUserName(userName);



        response.setContentType("text/xml;
charset=UTF-8"
);



            response.setHeader("Cache-Control", "no-cache");



           



            //创建输出流对象



            PrintWriter out =
response.getWriter();



            //依据验证结果输出不同的数据信息



            out.println("<response>");  



            if(arr_oaSchedule.size()!=0){



                for(int
i=0;i<arr_oaSchedule.size();i++){



                  OaSchedule
oaSchedule=(OaSchedule)arr_oaSchedule.get(i);



                  Date now=new Date();



                  Date date=oaSchedule.getRemindTime();



                  Boolean ture=date.before(now);



                  if(ture&&oaSchedule.getRemind()==null){



                     out.println("<id>" +
oaSchedule.getId() +
"</id>");



                     out.println("<content>" +
oaSchedule.getContent() +
"</content>");



                     out.println("<remindtime>" +
time(oaSchedule.getRemindTime()) +
"</remindtime>");



                     out.println("<starttime>" +
time(oaSchedule.getStartTime()) +
"</starttime>");



                  }



                 



                }



            }



            else {



            out.println("<id>0</id>");



             out.println("<content></content>");



             out.println("<remindtime></remindtime>");



             out.println("<starttime></starttime>");



            }



           out.println("</response>");



           out.close();



          



        }



        if(action.equalsIgnoreCase("get1")){



        ArrayList arr_oaSchedule=(ArrayList)oaScheduleService.findByUserName(userName);



        response.setContentType("text/xml;
charset=UTF-8"
);



            response.setHeader("Cache-Control", "no-cache");



           



            //创建输出流对象



            PrintWriter out =
response.getWriter();



            //依据验证结果输出不同的数据信息



            out.println("<response>");  



            if(arr_oaSchedule.size()!=0){



                for(int
i=0;i<arr_oaSchedule.size();i++){



                  OaSchedule
oaSchedule=(OaSchedule)arr_oaSchedule.get(i);



                     out.println("<id>" +
oaSchedule.getId() +
"</id>");



                     out.println("<content>" + transform(oaSchedule.getContent())
+
"</content>");



                     out.println("<remindtime>" +
time(oaSchedule.getRemindTime()) +
"</remindtime>");



                      out.println("<starttime>" + time(oaSchedule.getStartTime()) + "</starttime>");   



                     if(i==3)break;



                }



            }



            else {



            out.println("<id>0</id>");



             out.println("<content></content>");



             out.println("<remindtime></remindtime>");



             out.println("<starttime></starttime>");



            }



           out.println("</response>");



           out.close();



          



        }



       return null;



    }



    public String time(Date date1){



    String year=String.valueOf(date1.getYear()+1900);



    String month=String.valueOf(date1.getMonth());



    if(date1.getMonth()<10)



    month="0"+month;



    String date=String.valueOf(date1.getDate());



    if(date1.getDate()<10)



    date="0"+date;



    String hour=String.valueOf(date1.getHours());



    if(date1.getHours()<10)



    hour="0"+hour;



    String min=String.valueOf(date1.getMinutes());



    if(date1.getMinutes()<10)



    min="0"+min;



    String time=year+"-"+month+"-"+date+" "+hour+":"+min;



    return time;



 



    }



    public static String transform(String content)



    {



    content=content.replaceAll("&","&amp;");



    content=content.replaceAll("<","&lt;");



//  content=content.replaceAll(" ","&nbsp;");



    content=content.replaceAll(">","&gt;");



//  content=content.replaceAll("/n","<br>");



    return content;



    }



 



 



 



if(action.equalsIgnoreCase("get")){



          



           ArrayList
arr_oaMessage=(ArrayList)
oaMessageService.findByUserName(userName);



          
response.setContentType(
"text/xml;
charset=UTF-8"
);



            response.setHeader("Cache-Control", "no-cache");



           



            //创建输出流对象



            PrintWriter out =
response.getWriter();



            //依据验证结果输出不同的数据信息



            out.println("<response>");  



            if(arr_oaMessage.size()!=0){



                for(int
i=0;i<arr_oaMessage.size();i++){



                  OaMessage
oaMessage=(OaMessage)arr_oaMessage.get(i);



                   String
content=oaMessage.getContent();



                   content=transform(content);



                     out.println("<id>" +
oaMessage.getId() +
"</id>");



                     out.println("<fromUserName>" +
oaMessage.getFromUserName() +
"</fromUserName>");



                     out.println("<content>" + content + "</content>");



                     out.println("<time>" +
oaMessage.getTime() +
"</time>");



                     if(i==3)break;



                }



            }



            else {



            out.println("<id>0</id>");



            out.println("<fromUserName></fromUserName>");



            out.println("<content></content>");



            out.println("<time></time>");



            }



           out.println("</response>");



           out.close();



        }