594   Java JS

1,前端ajax请求,指定dataType为json,但是后端返回不是json,即使有返回数据,但是ajax的status依然为不成功,所以无法进入success

		$.ajax({
                url : url,
                dataType : "json",
                type : "get",
                timeout : 50000,
                data : {
                	
                },
                success : function(data) {
                    console.log("data:"+data);
                }

	        complete : function(XMLHttpRequest,status){
                    console.log("status:"+status);
                }
        });

2,后端返回字符串为默认编码ISO-8859-1,但是前端编码为utf-8,导致中文全部变成问号,解决方法:后端方法添加注解


	@ResponseBody
        // 添加注解,指定编码和content-type
	@RequestMapping(value="/chartsByGraphId", produces="text/html;charset=UTF-8")
	public String chartsByGraphId(HttpServletRequest request,HttpServletResponse response) {


         // your code 

        }



Leave a Reply

Your email address will not be published. Required fields are marked *