您的位置:首页 > 编程语言 > Java开发

ajax配合java简单案例

2015-12-24 14:55 441 查看
双重AJAX的案例

function select(){

$.ajax({//AJAX执行

type : 'POST',

url : '${ctx}/dingDanSelect.chtml',

dataType : 'text',

data : {

"creatTime" : $("#creatTime").val(),

"orderId" : $("#orderId").val()

},

success : function(data) { //正确执行得到数据,进行回调函数处理

if (data == 'ok') {//通过校验

tonewpage();

} else if (data == 'false') {

$("#showconent").empty();

$("#alert").show();

$(".lightbox-shadow").show();

var b ="<p2>此订单是否已完成支付?</p2><br/><br/><br/><br/>"

b=b+"<a onclick='colsed();' id='alertMessage-center-link1' href='#' style='margin: 0px auto; padding: 20px; color: #438EB9'>是</a>"//关闭窗口

b=b+"<a onclick='savePayOrder();' id='alertMessage-center-link2' href='#' style='margin: 0px auto; padding: 20px; color: #438EB9'>否</a> "//继续支付

$("#showconent").append(b);

}else if (data == 'false') {

$("#showconent").empty();

$("#alert").show();

$(".lightbox-shadow").show();

var b ="<p>该订单订单已经超时,无法继续付款!</p>"

b=b+"<a id='alertMessage-center-link' href='${ctx}/app/index.chtml'>确定</a> "

$("#showconent").append(b);

}

},

error : function() {

}

});

}

后来JAVA接受的代码部分

import java.io.PrintWriter;

import java.io.UnsupportedEncodingException;

import java.net.URLEncoder;

import java.security.MessageDigest;

import java.sql.SQLException;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.Calendar;

import java.util.Date;

import java.util.List;

import java.util.Random;

import javax.servlet.http.Cookie;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;

import net.sf.json.JSONObject;

import org.apache.commons.lang3.StringUtils;

import org.apache.log4j.Logger;

import org.jasig.cas.client.authentication.AttributePrincipal;

import org.jasig.cas.client.util.AssertionHolder;

import org.jasig.cas.client.validation.Assertion;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.RequestParam;

@RequestMapping(value = "/dingDanSelect", method = RequestMethod.POST)

public void checkStoreName(HttpServletRequest request, HttpServletResponse response,

@RequestParam("creatTime") String creatTime,@RequestParam("orderId") String orderId) {

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

out.print("time");//该订单超时

out.flush();

out.close();

}

}

带数据形式的

function tonewpage(){//获得跳转地址

$.ajax({

type : 'POST',

url : '${ctx}/app/dingDanTiaoZhuan.chtml',

dataType : 'text',

data : {

"creatTime" : $("#creatTime").val(),

"orderId" : $("#orderId").val()

},

success : function(msg) {

var per = eval(msg);

for ( var i = 0; i < per.length; i++) {

paUrl=per[i];

savePayOrder();//per[i];

// self.location=per[i];

}

},

});

}

@RequestMapping(value = "/dingDanSelect", method = RequestMethod.POST)

public void checkStoreName(HttpServletRequest request, HttpServletResponse response,

@RequestParam("creatTime") String creatTime,@RequestParam("orderId") String orderId) {

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

List listUrl=new ArrayList();

listUrl.add(urlAll);

JSONArray jsarr = JSONArray.fromObject(listUrl);

PrintWriter out = response.getWriter();

out.print(jsarr.toString());

out.flush();

out.close();

out.flush();

out.close();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: