jquery 跨域发送请求 java做服务端

jquery格式如下:

function runTask(){
         $.getJSON($server+"/runTask?callback=?",{start:$("#transDateStart").val(),end:$("#transDateEnd").val()}, function(json){      
                var result=json.ret;
                if(result=='1'){
                        $.ligerDialog.success('任务执行完成','执行结果');
                }else if(result=='2'){
                        $.ligerDialog.error('日期输入有误','执行结果');
                }else if(result=='3'){
                        $.ligerDialog.error('日期不能全部为空','执行结果');
                }else{
                        $.ligerDialog.error('任务执行失败','执行结果');
                }
                 }); 
      }

服务端接受代码如下:

@RequestMapping(value = "/runTask", method = RequestMethod.GET) 
public void runTask(HttpServletRequest request, HttpServletResponse response, String start, String end) throws IOException {
                response.setContentType("text/javascript");
                response.setCharacterEncoding("utf8");
                PrintWriter out = response.getWriter();
                String callback = request.getParameter("callback");

                out.print(callback + " ({ ret:'" + resultCode + "'} );");
                out.print(callback);
                out.flush();

};


你可能感兴趣的:(jquery)