创建一个json对象
var obj = {};
obj.productId = productId + "|" + parseInt($("#buyNum").text()) ;
obj.payType = payType;
obj.tRealPrice = tRealPrice;
obj.tIntegral = tIntegral;
obj.cardNo = bankId;
obj.payToken = $("#payToken").val();
//可以根据不同条件传递添加属性
if(from == "luck"){
var luck_tPromotionAdId = $("#luckInfo").data("luck_tPromotionAdId");
var luck_tSchedule = $("#luckInfo").data("luck_tSchedule");
var luck_tActivityId = $("#luckInfo").data("luck_tActivityId");
if($.ckIsEmpty(tPromotionAdId)){
obj.tPromotionAdId = tPromotionAdId ;
}
obj.tSchedule = luck_tSchedule ;
obj.tActivityId = tActivityId
}
ajax 使用json对象参数
$.ajax({
type : "post",
url : $.ckGetContext() + '/pay/doPayOrder',
data : obj,
dataType : "json",
success : function(data){
var json = $.ckObjToJsonStr(data.cmbData);
$('body').append("<form id='ckForm' style='display: none;' method='post'></form>");
$("#ckForm").attr({"action":data.cmbaddress});
var input = '<input name="jsonRequestData" value=\'' + json + '\' type="hidden">';
$("#ckForm").append(input);
$("#ckForm").submit();
},
error : function(msg){
alert(msg)
}
});
总结:当ajax的dataType为“json”时,返回 json 数据