@RequestMapping(value="/crossAjax")
@ResponseBody
public String crossAjax(HttpServletRequest request){
String callback=request.getParameter("callback");
System.out.println("-----" + callback);
System.out.println("-----" + request.getParameter("query"));
JSONObject obj=new JSONObject();
try {
obj.put("message", "test1");
obj.put("time", "test1");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(obj.toString());
return callback + "(" + obj.toString() + ")";
}
$.ajax({
url : "http://127.0.0.1:8080/home/crossAjax",
data : {query:"select * from ssssss"},
dataType : "jsonp",
jsonp : "callback",
success: function(data) {
console.log('성공 - ', data);
},
error: function(xhr) {
alert('실패 - ' + xhr.statusText);
}
});
댓글 없음:
댓글 쓰기