jquery $.get()方法使用
2014-04-24 14:28
393 查看
<div class="me-important-tip" id="important-tip" style="display: block; "><span id="tips" style=""></span>
<a href="" class="important-tip-close" id="important-tip-close">closed</a>
</div>
$.get("ajaxWeatherStat.action", {}, function (data, textStatus){
var ajaxData;
eval("ajaxData = " + data );
$("#tips")[0].style.color= ajaxData.color;
$("#tips")[0].innerHTML = ajaxData.warning;
//setTimeout(function(){$("#important-tip")[0].style.display = "none";},5000);
});
/**
*
* Description : ajax 查询天气获取情况统计</br>若没有当天的前一天的数据,红色字体显示警告。没有当天的天气数据,蓝色字体显示提示。有当天的天气数据,黑色字体显示信息。
*
*
*/
public void ajaxQueryWeatherGetInfo()
{
logger.enterFuncDebugLog();
String wordColor = "black";
warning = "";
try
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String date = sdf.format(new Date());
String datebak = date;
List<Weather> list = weatherService.getWeatherByDate(date);
if (list == null || list.size() <= 0)
{
// 没有当天的天气,蓝色警告
wordColor = "blue";
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, -1);
date = sdf.format(new Date(calendar.getTimeInMillis()));
list = weatherService.getWeatherByDate(date);
if (list == null || list.size() <= 0)
{
// 没有前一天的天气,红色警告
wordColor = "red";
warning = this.getText(Constants.MSG_PORTALMS + "weatherMgr.noBeforeWeather", new String[] {
datebak, date });
}
else
{
warning = this.getText(Constants.MSG_PORTALMS + "weatherMgr.noCurrentWeather", new String[] {
datebak, date, String.valueOf(list.size()), date });
}
}
else
{
warning = this.getText(Constants.MSG_PORTALMS + "weatherMgr.hasWeather", new String[] { date,
String.valueOf(list.size()) });
}
toUTF8("{color:'" + wordColor + "',warning:'" + warning + "'}");
}
catch (Exception e)
{
e.printStackTrace();
toUTF8("{color:'red',warning:'"
+ PropertiesFactory.getValueString(ChineseCharacter.WEATHERACTION_STATISTICS_FAILED) + "'}");
logger.excepFuncDebugLog("Check the weather gets statistics failed");
}
logger.exitFuncDebugLog();
}
public void toUTF8(String jsonString)
{
HttpServletResponse response = ServletActionContext.getResponse();
response.setHeader("Cache-Control", "no-cache");
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("utf-8");
try
{
response.getWriter().print(jsonString);
}
catch (Exception e)
{
}
}
<a href="" class="important-tip-close" id="important-tip-close">closed</a>
</div>
$.get("ajaxWeatherStat.action", {}, function (data, textStatus){
var ajaxData;
eval("ajaxData = " + data );
$("#tips")[0].style.color= ajaxData.color;
$("#tips")[0].innerHTML = ajaxData.warning;
//setTimeout(function(){$("#important-tip")[0].style.display = "none";},5000);
});
/**
*
* Description : ajax 查询天气获取情况统计</br>若没有当天的前一天的数据,红色字体显示警告。没有当天的天气数据,蓝色字体显示提示。有当天的天气数据,黑色字体显示信息。
*
*
*/
public void ajaxQueryWeatherGetInfo()
{
logger.enterFuncDebugLog();
String wordColor = "black";
warning = "";
try
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String date = sdf.format(new Date());
String datebak = date;
List<Weather> list = weatherService.getWeatherByDate(date);
if (list == null || list.size() <= 0)
{
// 没有当天的天气,蓝色警告
wordColor = "blue";
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, -1);
date = sdf.format(new Date(calendar.getTimeInMillis()));
list = weatherService.getWeatherByDate(date);
if (list == null || list.size() <= 0)
{
// 没有前一天的天气,红色警告
wordColor = "red";
warning = this.getText(Constants.MSG_PORTALMS + "weatherMgr.noBeforeWeather", new String[] {
datebak, date });
}
else
{
warning = this.getText(Constants.MSG_PORTALMS + "weatherMgr.noCurrentWeather", new String[] {
datebak, date, String.valueOf(list.size()), date });
}
}
else
{
warning = this.getText(Constants.MSG_PORTALMS + "weatherMgr.hasWeather", new String[] { date,
String.valueOf(list.size()) });
}
toUTF8("{color:'" + wordColor + "',warning:'" + warning + "'}");
}
catch (Exception e)
{
e.printStackTrace();
toUTF8("{color:'red',warning:'"
+ PropertiesFactory.getValueString(ChineseCharacter.WEATHERACTION_STATISTICS_FAILED) + "'}");
logger.excepFuncDebugLog("Check the weather gets statistics failed");
}
logger.exitFuncDebugLog();
}
public void toUTF8(String jsonString)
{
HttpServletResponse response = ServletActionContext.getResponse();
response.setHeader("Cache-Control", "no-cache");
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("utf-8");
try
{
response.getWriter().print(jsonString);
}
catch (Exception e)
{
}
}
相关文章推荐
- JQuery的get、post和ajax方法的使用
- JQuery------$.get()和$.post()传递数据的使用方法
- 使用jQuery的ajax方法向服务器发出get和post请求的方法
- jquery中eq和get的区别与使用方法
- 使用Jquery中getJSON和getScript方法实现跨域
- 11-Jquery使用get方法实现用户名的验证
- jquery中get,post和ajax方法的使用小结
- jquery中 $.getJSON 的使用方法
- jQuery的ajax()检验用户名;通过jQuery的load()/get()/post()方法实现;使用XMLHTTPRequest对象来进行AJAX的异步数据交互
- jquery中$.getJSON 的使用方法
- JQuery的Ajax使用Get,Post方法调用C#WebService并返回数据
- 使用jQuery的getJSON方法实现配置信息的状态的异步修改
- jquery使用$.getJson()跨域大数据量请求方法
- 【jQuery】使用get()方法以GET方式从服务器获取数据
- jquery中get,post和ajax方法的使用小结
- jquery eq 与 get使用方法
- JQuery中getJSON的使用方法(转)
- post 和 get比较、jquery和dom比较、jquery中eq和get使用、jquery常用方法、集合处理功能
- JQuery中getJSON的使用方法
- 为您解惑:jQuery中$.getJSON( )的使用方法简介之获取JSON格式的数据.........