ajax实现跨域请求

		function load(){
 				//执行跨域请求
                $.ajax({
                    url: "http://localhost:8080/all/process/test",
                    type: "get",
                    dataType: "jsonp",
                    jsonp: "callback",   //指定参数名称
                    jsonpCallback: "doSuccess",  //指定回调函数名称
                    success: function(result) {
                        console.log("jsonp");
                        console.log(result);
                    }
                })
           }
           
	function doSuccess(result){
 				console.log("result",result);
           }

    //测试跨域请求
    @RequestMapping(value="/test", method = RequestMethod.GET)
    @ResponseBody
    public Strng test(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String result="\"{name:zs,age:24}\"";
        String callback = request.getParameter("callback");
        result = callback + "(" + result + ")";
        System.out.println(result);
        return result;
//        return result;
    }

你可能感兴趣的:(js,跨域,java,js,java,ajax,ajax跨域问题)