jquery了解-使用ajax
jquery了解-使用ajax
嘿嘿,一直听同事介绍jquery的好处,但是以前用过点点,现在终于有机会开始接触一下了。
今天需求要调用下ajax,已经不想使用dwr了,想把这些业务留在我的controller层面。
jquery首页
http://jquery.com/
下载地址
http://code.google.com/p/jqueryjs/downloads/list
参考文章
http://www.ibm.com/developerworks/cn/xml/x-ajaxjquery.html
核心js如下:
function updateCharts() {
//ajax调用
$.ajax({
url: 'http://localhost:8080/easyfusion/user/countuser.do',
type: 'POST',
dataType: 'text',//返回文本
timeout: 1000,
error: function(){
alert('Error loading XML document');
},
success: function(text){
updateChartXML("SalesByProd", text);//用返回的文本当参数,调用另外一个函数画出图形
}
});
}
其中我的countuser.do是这么书写的:
@RequestMapping("/user/countuser.do")
public ModelAndView countuser(HttpServletRequest request,
HttpServletResponse response) throws Exception {
return new ModelAndView("jsp/data2");
}
返回的jsp页面是data2.jsp,这样好调试:
<%@ page language="java" contentType="text/xml; charset=GBK"
pageEncoding="GBK"%>
<?xml version="1.0" encoding="GBK"?>
<graph xaxisname='Continent' yaxisname='Export' hovercapbg='DEDEBE'
hovercapborder='889E6D' rotateNames='0' yAxisMaxValue='100'
numdivlines='9' divLineColor='CCCCCC' divLineAlpha='80'
decimalPrecision='0' showAlternateHGridColor='1' AlternateHGridAlpha='30'
AlternateHGridColor='CCCCCC' caption='人员统计' shownames='1'
showvalues='1' decimals='0' formatNumberScale='0' baseFont='Tahama'
baseFontSize='12'>
<categories>
<category label='Chang' />
<category label='Chartreuse verte' />
<category label='Guaran Fantstica' />
<category label='Lakkalikri' />
<category label='Outback Lager' />
<category label='Rhnbru Klosterbier' />
<category label='Steeleye Stout' />
</categories>
<dataset seriesname='Revenue' color='FDC12E'>
<set value='1995' />
<set value='864' />
<set value='194' />
<set value='270' />
<set value='615' />
<set value='93' />
<set value='360' />
</dataset>
<dataset seriesName='Units Sold' parentYAxis='S' color='56B9F9'>
<set value='105' />
<set value='48' />
<set value='43' />
<set value='15' />
<set value='41' />
<set value='12' />
<set value='20' />
</dataset>
</graph>