贴点自己的代码吧。
AJAX提交后台json代码,获取返回值。
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> <script type="text/javascript"> function test(){ alert("dafadsfa"); var xmlHttp; if(window.XMLHttpRequest){ xmlHttp=new XMLHttpRequest(); } else if(window.ActiveXObject){ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } var saveJson='{' +' "productInfo": {' +' "insured_count": "1",' +' "productPrice": "45",' +' "startDate": "2015-05-31 00:00:00",' +' "endDate": "2015-05-31 23:59:59",' +' "productName": "测试产品",' +' "showPeriod": "1D",' +' "productId": "203401010",' +' "productApp": "|00000000000000003476_Period=1D|00000000000000003475_TextAge=0Y-80Y|' +'00000000000000003483_Mult=1|00000000000000003484_AppDate=2D", ' +' "productDuty": "", ' +' "shareId": "" ' +' }, ' +' "SDInformationAppnt": [ ' +' { ' +' "applicantName": "尚小梅", ' +' "applicantIdentityTypeName": "身份证号码", ' +' "applicantIdentityId": "", ' +' "applicantMail": "", ' +' "applicantMobile": "" ' +' } ' +' ], ' +' "SDInformationInsured": [ ' +' { ' +' "recognizeeName": "尚小梅", ' +' "recognizeeIdentityTypeName": "身份证号码", ' +' "recognizeeIdentityId": "", ' +' "recognizeeMobile": "", ' +' "flightTime": "2015-07-19", ' +' "recognizeeMail": "", ' +' "isSelf": "Y", ' +' "recognizeeBirthday": "" ' +' } ' +' ], ' +' "SDInformationProperty": [ ' +' { ' +' "remark1": "" ' +' } ' +' ] ' +'} '; xmlHttp.onreadystatechange=function() { if (xmlHttp.readyState==4 &&xmlHttp.status==200) { document.getElementById("myDiv").innerHTML=xmlHttp.responseText; } } //配置XMLHttpRequest对象 xmlHttp.open("post", "../../shop/wap_order!saveOrdersInfo.action",true); //xmlHttp.open("post", "http://219.141.188.60:9080/shop/wap_order!saveOrdersInfo.action",true); xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); //发送请求 xmlHttp.send("saveJson="+saveJson); } </script> </head> <body> <input type="button" value="提交" onclick="test()"> <div id="myDiv"/> </body> </html>