您的位置:首页 > Web前端 > JQuery

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)

        {

        }

    }   
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: