ajax 后台调用,ajax跨域调用和后台的接口的方法

一:java后台

public void getNotices() {

String callback = getPara("callback");

List notices = NoticeService.me.getNotices();

if (null == callback || callback.trim().equals("")) {

renderJson(notices);

} else {

renderJson(callback + "(" + notices + ")");

}

}

二:页面ajax

function a() {

$.ajax({

url : "http://hjsgzh.xxx.com/notice/getNotices",

data : {

name : '篮球',

},

type : "post",

dataType : "jsonp",

jsonp : "callback",

async : false,

error : function(error) {

console.log(error);

},

success : function(res) {

console.log(res);

}

})

}

三:小结

jsonp的值就是后台获取的参数名字