jquery $.get()方法使用

<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)
        {
        }
    }   
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值