加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ajax的接收格式和传输json格式种类和方式

发布时间:2020-12-16 03:17:57 所属栏目:百科 来源:网络整理
导读:(一)ajax返回格式 1, 默认 返回字符串,页面也会转成字符串(text) 参考: http://www.cnblogs.com/bujianchenxi/p/6060799.html 2返回页面 $.ajax({ type:'post', url:'后台路径', dataType:' html ', success:function(result){ //console.info(result

(一)ajax返回格式

1,默认返回字符串,页面也会转成字符串(text)

参考:

http://www.cnblogs.com/bujianchenxi/p/6060799.html

2返回页面

$.ajax({

type:'post',

url:'后台路径',

dataType:'html',

success:function(result){

//console.info(result);

$("#test").html(result);

}

});

注意:dataType:'html'为html类型,后台实现,如下:

@RequestMapping(value = "test")

public String test(Model model) {

model.addAttribute("test","test");

return "modules/test/test";

}

return一个页面,例如上面的对应的视图为test.jsp

参考:

http://blog.csdn.net/menghuannvxia/article/details/49664059

http://blog.csdn.net/liu765023051/article/details/45308827

3,ajax json 前台接收解析

var dataJsonObject = JSON.parse(data);

if (dataJsonObject.returnCode == 1 ) {

(二)ajax传输json格式:

ajax json 前台打包传输

遇到“”里面套用“”需要转义

1,使用转义符,此时不需要JSON.stringify()后传递过去(整个不用引号引起)

var jsonsWxInFo="{"result":{" +

""baseInfo":{"liveAddress":"","tenementCity":"","homePhone":"","tenementAddress":"","qqAccount":"","hasTenement":"","liveCity":"","monthSalary":"","educationLevel":"","marriage":"","id":"","weixinAccount":"","tenementType":"","email":"","hasCar":"","liveStarttime":""}," +

""contactInfo":{"immediateFamilyIdcard":"","postAddress":"","spousePhone":"","contactPerson":"","contactPersonPhone":"","getProductWay":"","immediateFamilyPhone":"","contactPersonRelation":"","spouse":"","nonImmediateFamilyName":"","nonImmediateFamilyRelation":"","immediateFamilyName":"","spouseIdcard":"","nonImmediateFamilyPhone":"","immediateFamilyRelation":"","isFamilyKnow":"","marryDate":""}," +

""policyInfo":{"actualYear":"","policyName":"","inputUserid":"","shouldYear":"","inputDate":"","paymentType":"","lifeInsuranceYearSum":"","inputOrgId":"","monthAmt":"","useDate":"","policyCount":"","policyType":"","customerId":"","insuranceName":"","policyIndex":""}," +

""additionalInfo":{"otherIdentityPicUrl":"","otherPicUrl":"","loanPicUrls":"","juzhuzhengPicUrls":"","creditCardPicUrls":"","hukoubenPicUrls":"","gongzuozhengPicUrls":"","identityFrontPicUrl":"bluckname=test&imgName=MTExLnBuZzE1MDc3MDkzNTkxNzI=.png","identityBackPicUrl":"","marriageCertificatePicUrls":"","zichanLetterPicUrls":"","id":"4","shouruLetterPicUrls":""}," +

""additionalInfoRemarks":{"dealUserid":"","createTime":"","dealUsername":"","remark":"","id":""}," +

""applyInfo":{"loanTerm":"","purpose":"","applyAmount":""}," +

""careerInfo":{"jobName":"","reserveFundsRadix":"","salaryDate":"","companyCity":"","companyType":"","hasSocialSecurity":"","industry":"","jobLevel":"","industryForth":"","salaryWithoutTax":"","employeeType":"","companyPhone":"","industrySecond":"","companyAddress":"","industryThird":"","company":"","department":"","socialSecurityRadix":"","employeeAmount":""}," +

""creditInfo":{"bankPicUrls":"","peopleBankPicUrls":"","reserveFundsPicUrls":"","id":""}}," +

""orderNo":"A001","state":"","isEiditAble":"1"}";

function saveDetailWX(){

alert(6);

$.ajax({

url: '${ctx}/itm/weixin/saveWXOrderInfo.action',

data: {

jsonsWxInFo: jsonsWxInFo // 图片数据流

},

dataType: 'json',

type: 'post',

success: function(data) {

var dataJsonObject = JSON.parse(data);

if (dataJsonObject.returnCode == 'A0001' ) {

}else{

alert('图片上传失败!');

}

},

error: function(xhr,type,errorThrown) {

alert('网络异常,请稍后再试!');

}

});

}

2,不使用转义符,此时用JSON.stringify()将数据传递过去

var jsonsWxInFo={"result":{

"baseInfo":{"liveAddress":"","tenementCity":"","homePhone":"","tenementAddress":"","qqAccount":"","hasTenement":"","liveCity":"","monthSalary":"","educationLevel":"","marriage":"","id":"","weixinAccount":"","tenementType":"","email":"","hasCar":"","liveStarttime":""},

"contactInfo":{"immediateFamilyIdcard":"","postAddress":"","spousePhone":"","contactPerson":"","contactPersonPhone":"","getProductWay":"","immediateFamilyPhone":"","contactPersonRelation":"","spouse":"","nonImmediateFamilyName":"","nonImmediateFamilyRelation":"","immediateFamilyName":"","spouseIdcard":"","nonImmediateFamilyPhone":"","immediateFamilyRelation":"","isFamilyKnow":"","marryDate":""},

"policyInfo":{"actualYear":"","policyName":"","inputUserid":"","shouldYear":"","inputDate":"","paymentType":"","lifeInsuranceYearSum":"","inputOrgId":"","monthAmt":"","useDate":"","policyCount":"","policyType":"","customerId":"","insuranceName":"","policyIndex":""},

"additionalInfo":{"otherIdentityPicUrl":"","otherPicUrl":"","loanPicUrls":"","juzhuzhengPicUrls":"","creditCardPicUrls":"","hukoubenPicUrls":"","gongzuozhengPicUrls":"","identityFrontPicUrl":"bluckname=test&imgName=MTExLnBuZzE1MDc3MDkzNTkxNzI=.png","identityBackPicUrl":"","marriageCertificatePicUrls":"","zichanLetterPicUrls":"","id":"4","shouruLetterPicUrls":""},

"additionalInfoRemarks":{"dealUserid":"","createTime":"","dealUsername":"","remark":"","id":""},

"applyInfo":{"loanTerm":"","purpose":"","applyAmount":""},

"careerInfo":{"jobName":"","reserveFundsRadix":"","salaryDate":"","companyCity":"","companyType":"","hasSocialSecurity":"","industry":"","jobLevel":"","industryForth":"","salaryWithoutTax":"","employeeType":"","companyPhone":"","industrySecond":"","companyAddress":"","industryThird":"","company":"","department":"","socialSecurityRadix":"","employeeAmount":""},

"creditInfo":{"bankPicUrls":"","peopleBankPicUrls":"","reserveFundsPicUrls":"","id":""}},

"orderNo":"A001","state":"","isEiditAble":"1"};

function saveDetailWX(){

alert(6);

$.ajax({

url: '${ctx}/itm/weixin/saveWXOrderInfo.action',

data: {

jsonsWxInFo: JSON.stringify(jsonsWxInFo) // 图片数据流

},errorThrown) {

alert('网络异常,请稍后再试!');

}

});

}

后台json结构数据和实体转化

public String saveWXOrderInfo(){

QueryOrderDetailReqqp=(QueryOrderDetailReq)JSONObject.toBean(JSONObject.fromObject(jsonsWxInFo),QueryOrderDetailReq.class);

//baseService.save();

BaseResp br = new BaseResp();

br.setReturnCode(WeixinErrorMsg.SUCCESS.getCode());

br.setReturnMsg(WeixinErrorMsg.SUCCESS.getText());

result= JSONObject.fromObject(br).toString();

return SUCCESS;

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读