JQuery的跨域调用

$('#test').click(function(){
    var getDataURL="http://www.qq.com/xxx/xx/xx/x/data?callback=?";
$.ajax({
	url:getDataURL,
	type:"get",
	dataType:"jsonp",				
	success:function(data) {
		alert(data.MODULUS);  
		alert(data.PUBLIC_EXPONENT);
	},
	error:function (XMLHttpRequest, textStatus, errorThrown) {					alert("出现错误:"+textStatus);
	}
	});
		
});
@RequestMapping(value = Url.GET_RSA_MODULUS_URL, method = RequestMethod.GET)
	public void getModulus(String callback, HttpServletResponse response, ModelMap modelMap) {
		
		response.setContentType("application/json; charset=utf-8");
		String str = "{\"MODULUS\":\"" + RSAVariable.MODULUS + "\",\"PUBLIC_EXPONENT\":\""
				+ RSAVariable.PUBLIC_EXPONENT + "\"}";
		try {

			response.getWriter().write(callback + "(" + str + ")");
		} catch (Exception e) {
			try {
				e.printStackTrace();
				response.getWriter().write("{\"msg\":\"" + e.getMessage() + "\"}");
			} catch (Exception ex) {
			}
		}
	}

你可能感兴趣的:(JQuery的跨域调用)