jquery跨域调用实例:
js:
var receiveCode = {
receive : function(){
var gacId = $(“input[name=’gacId’]”).val();
$.getJSON(“receiveActiveCard.do?jsonpCallback=?”,{gacId:gacId},function(data){
$(“#content”).html(‘<span class=”tipText”>’+’ ‘+'</span>’);
if(data.error!=undefined){
alert(data.error);
}
var isLog = data.loginState;
if(isLog == ‘0’){
alert(‘网页已过期’);
window.location.reload();
}else{
if(data.receiveState!=null&&’1’==data.receiveState){
$(“#content”).append(‘<span style=”color:red”>已经领取完毕!</span> ‘);
}else{
if(”!=data.activecardno){
$(“#content”).append(‘<p class=”text”><span class=”get_title”>’+’卡号: ‘+data.activecardno+'</span></p>’);
}
if(”!=data.activecardpass){
$(“#content”).append(‘<p class=”text”><span class=”get_title”>’+’密码: ‘+data.activecardpass+'</span></p>’);
}
}
}
});
}
}
action:
/******************************
* 版权所有:顺网科技 保留所有权利
* 创建日期: Apr 20, 2011 10:32:52 AM
* 创建作者:hutaisi
* 文件名称:
* 版本: 1.0
* 功能:
* 最后修改时间:
* 修改记录:
****************************************/
public class CardReceiveRecordAction extends ExpandAction {
private final Logger logger = LoggerFactory.getLogger(LoginAction.class);
private CardReceiveRecordBO cardReceiveRecordBO;
private Integer gacId;
private String jsonpCallback;
private String receiveValidateCode;
/**
* 直接领号
* @return
*/
public String receiveActiveCard(){
PageStateInfo pageStateInfo = new PageStateInfo();
String outInfo = null;
if(gacId!=null){
ActiveCard activeCard = cardReceiveRecordBO.receiveActiveCard(“default”, gacId);
if(activeCard!=null){
outInfo = activeCard.toJsObject().toString();
logger.info(“默认用户领取新手卡”);
}else{
pageStateInfo.setReceiveState(Context.IS_RECEIVE);
outInfo = pageStateInfo.toJsObject().toString();
logger.info(“激活卡:”+gacId+”已经领取完!”);
}
}
outMsg(jsonpCallback+”(“+outInfo+”)”);
return null;
}
public Integer getGacId() {
return gacId;
}
public void setGacId(Integer gacId) {
this.gacId = gacId;
}
public String getJsonpCallback() {
return jsonpCallback;
}
public void setJsonpCallback(String jsonpCallback) {
this.jsonpCallback = jsonpCallback;
}
public String getReceiveValidateCode() {
return receiveValidateCode;
}
public void setReceiveValidateCode(String receiveValidateCode) {
this.receiveValidateCode = receiveValidateCode;
}
public CardReceiveRecordBO getCardReceiveRecordBO() {
return cardReceiveRecordBO;
}
public void setCardReceiveRecordBO(CardReceiveRecordBO cardReceiveRecordBO) {
this.cardReceiveRecordBO = cardReceiveRecordBO;
}
}