ajax的交互问题:
关于dataType:Json,后台如果返回单纯的字符串这是用这个就接不到回调值,
后台如果返回的是json格式的字符串,那么用这个就会将这个格式的字符串转化为json对象作为回调值
后台的返回也有两种方式:
1,加@responseBody
2,直接用response.getWriter().write();
都会返回回调,只要dataType和后台的一致即可
/**
*标的成交
*/
function applyInfoNew(objKey,ord_key,ORDPRICE_NO,NEW_PRICE,chatNum,ARTNFLAG,CNT_KEY){
var cnt_num=$("input[name='newNum']").val();
var orderPrice=$("input[name='orderPrice']").val();
jQuery.ajax({
async:true,
url:webUrl+"/chat/offer/buyInfo?cnt_price="+NEW_PRICE+"&conobj_key="+objKey+"&cnt_num="+chatNum,
cache:false,
timeout:10000,
datatype:"json",
success:function(data){
if(data.status=="1"){
alert(data.msg);
return;
}else{
alert(2);
if (confirm("您确认成交吗?")) {
var CONTRADE_KIND = $("input[name='contradeKind']").val();
alert(CONTRADE_KIND);
//document.form2.action=path+"/negotiate!applyNew.do?urlType=dicker&objKey="+objKey+"&conOrdPriceBean.ORD_KEY="+ord_key+"&conOrdPriceBean.ORDPRICE_NO="+ORDPRICE_NO+"&conOrdPriceBean.CONTRADE_KIND="+CONTRADE_KIND;
//document.form2.submit();
$.ajax({
url:webUrl+"/chat/offer/applyNew?urlType=dicker&objKey="+objKey+"&ord_key="+ord_key+"&ORDPRICE_NO="+ORDPRICE_NO+"&CONTRADE_KIND="+CONTRADE_KIND,
type:"post",
cache:false,
async:true,
dataType:"json",
data:$("#form2").serialize(),
success:function(ret){
if(ret.status=="1"){
alert(ret.status);
window.location.href="http://localhost:8081/web/conObj/buyDetail.do?txt_conobj_key="+objKey+"&txt_contrade_kind="+CONTRADE_KIND+"&pick_types=A&jianjibuynum=0&order_prices="+orderPrice+"&cdListKeyArrayFront="+""+"&buyNum="+chatNum+"&ARTNFLAG="+ARTNFLAG+"&CNT_KEY="+CNT_KEY+"&msg="+encodeURIComponent(ret.msg);
//window.location.href=webUrl+"/web/conObj/buyDetail.do?txt_conobj_key="objKey+"&txt_contrade_kind="+CONTRADE_KIND+"&pick_types=A&jianjibuynum=0&order_prices="+orderPrice+"&cdListKeyArrayFront="+"";
//$.zd.alert("提示信息","恭喜您已成交",function(){
//parent.location=webUrl+"/conObj!buyPrint.do?urlType=dicker&CNT_KEY="+ret.msg;
//});
}else{
alert(8);
alert(ret.msg);
window.location.href="http://localhost:8081/web/conObj/buyDetail.do?txt_conobj_key="+objKey+"&txt_contrade_kind="+CONTRADE_KIND+"&pick_types=A&jianjibuynum=0&order_prices="+orderPrice+"&cdListKeyArrayFront="+""+"&buyNum="+chatNum+"&ARTNFLAG="+ARTNFLAG+"&CNT_KEY="+CNT_KEY+"&msg="+encodeURIComponent(ret.msg);
//$.zd.alert("提示信息",ret.msg,function(){
//refreshInfoData();
//});
}
},
error:function(retMsg){
window.location.href="http://localhost:8081/web/conObj/buyDetail.do?txt_conobj_key="+objKey+"&txt_contrade_kind="+CONTRADE_KIND+"&pick_types=A&jianjibuynum=0&order_prices="+orderPrice+"&cdListKeyArrayFront="+""+"&buyNum="+chatNum+"&ARTNFLAG="+ARTNFLAG+"&CNT_KEY="+CNT_KEY+"&msg="+encodeURIComponent(retMsg.msg);
//window.location.hre="http://localhost:8081/web/siteindex.do";
//refreshInfoData();
}
});
}else{
return false;
}
}
},
error:function(XMLHttpResuest,textStatus,errorThrown){}
});
/**if(confirm("确认以价格"+NEW_PRICE+",成交?")){
var CONTRADE_KIND = $("input[name='CONTRADE_KIND']").val();
document.form2.action="${path}/NegotiateAction!applyNew.action?urlType=dicker&objKey="+objKey+"&conOrdPriceBean.ORD_KEY="+ord_key+"&conOrdPriceBean.ORDPRICE_NO="+ORDPRICE_NO+"&conOrdPriceBean.CONTRADE_KIND="+CONTRADE_KIND;
document.form2.submit();
}*/
}
@SuppressWarnings({ "unused", "rawtypes" })
@RequestMapping(value="/chat/offer/applyNew")
public String applyNew(@RequestParam(value="objKey") String objKey,
@RequestParam(value="urlType") String urlType,
@RequestParam(value="ord_key") String ord_key,
@RequestParam(value="ORDPRICE_NO") String ORDPRICE_NO,
@RequestParam(value="CONTRADE_KIND") String CONTRADE_KIND,
HttpSession session, HttpServletRequest request, HttpServletResponse response, Model model) throws EsteelException, IOException {
String cusUser = CASUtil.getCurrentUserName(session);
TbCusUser user = tbCusUserService.getTbCusUserByCusUserId(cusUser);
String cus_user_key = user.getCusUserKey();
Map param = new HashMap<String,Object>();
param.put("ORD_KEY", ord_key);
param.put("ORDPRICE_NO", ORDPRICE_NO);
param.put("CUS_USER_KEY", cus_user_key);
param.put("CONTRADE_KIND", CONTRADE_KIND);
Map applyMap = tbConObjService.applyConOrdPrice(param);
String outs=(String) applyMap.get("OUTPARA");
Map map1=new HashMap<String,Object>();
if(outs!=null&&!"".equals(outs)){
map1= parsePara(outs);
}else{
map1.put("ARTNFLAG", "-1");
map1.put("MSG", "返回参数为空!");
}
String ARTNFLAG = "";
String MSG2 = "";
String ORD_KEY = "";
String CNT_KEY = "";
String errorInfo = "";
if (map1 != null) {
ARTNFLAG = (String)map1.get("ARTNFLAG");
MSG2 = (String)map1.get("MSG");
ORD_KEY = (String)map1.get("ORD_KEY");
CNT_KEY = (String)map1.get("CNT_KEY");
}
response.setContentType("text/html;charset=utf-8");
if ((ARTNFLAG == null) || (!ARTNFLAG.equals("0")))
{
if ((MSG2 != null) && (!MSG2.equals(""))) {
//setStrJs("alert('" + MSG2 + "!');parent.refreshInfoData();");
//setStrIfRunJs("1");
String str = JSONUtils.valueToString(JSONObject.fromObject(new JsonMsg("-1", MSG2,ARTNFLAG,CNT_KEY)));
response.getWriter().write(str);
response.getWriter().flush();
return null;
}
//setStrJs("alert('成交议价失败!');parent.refreshInfoData();");
//setStrIfRunJs("1");
String str = JSONUtils.valueToString(JSONObject.fromObject(new JsonMsg("-1", "成交议价失败",ARTNFLAG,CNT_KEY)));
response.getWriter().write(str);
response.getWriter().flush();
return null;
}
Map contractMap = null;
if ((CNT_KEY != null) && (!CNT_KEY.equals(""))) {
contractMap = this.tbConObjService.getContractByCNT_KEY(Integer.valueOf(CNT_KEY));
}
if (contractMap != null) {
//getRequest().setAttribute("contractMap", contractMap);
//getRequest().setAttribute("CNT_KEY", CNT_KEY);
//setStrJs("alert('恭喜您已成交!');parent.parent.location=\"" + getRequest().getContextPath() + "/conObj!buyPrint.do?urlType=" + urlType + "&CNT_KEY=" + CNT_KEY + "\";");
//setStrIfRunJs("1");
String str = JSONUtils.valueToString(JSONObject.fromObject(new JsonMsg("1", CNT_KEY + "",ARTNFLAG,CNT_KEY)));
response.getWriter().write(str);
response.getWriter().flush();
return null;
}
//setStrJs("alert('恭喜您已成交!');parent.refreshInfoData();");
//setStrIfRunJs("1");
String str = JSONUtils.valueToString(JSONObject.fromObject(new JsonMsg("2", "恭喜您已成交",ARTNFLAG,CNT_KEY)));
response.getWriter().write(str);
response.getWriter().flush();
return null;
}