<!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"> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/json2.js"></script> </head> <body> <p>
<!--必须这个写--> <label for="fileField">File:</label> <input type="file" name="fileField" id="fileField"> </p> <p> <input type="button" value="Save Data" style="80" onclick="testSaveData()"> </p> <div style="600;background-color:#FCC389;height:200;overflow-x:hidden;overflow-y:scroll" id="showArea"> </div> </body> <script> function testGetUserInfo() { $.ajax({ url : '/apps/ctrlPage/getUser?code=1', type:"get", error : function(error){alert("系统错误.")}, success : function(result) { if (result) { $("#showArea").html(JSON.stringify(result)); } } }); } function testGetCheckResult() { $.ajax({ url : '/apps/ctrlPage/getResult?ckUserId=1', type:"get", error : function(error){alert("系统错误.")}, success : function(result) { if (result) { $("#showArea").html(JSON.stringify(result)); alert(result.params.checkResult.cataract); } } }); } function testSaveData() { var formData = new FormData(); formData.append("ckUserId",1);
// 不要忘记加[0] formData.append("photo",$("#photoFile")[0].files[0]); formData.append("eyePositionRecheck","[{name:"映光",result:"<检查结果>"},{name:"交替遮盖",result:"<检查结果>"},{name:"三棱镜遮盖",result:{near:"<近距结果>",far:"<远距结果>"}}]"); formData.append("refractiveRecheck","{od:{ball:'球径',column:'柱径'},os:{ball:'球径',column:'柱径'}}"); formData.append("conclusion",'结论'); $.ajax({ url : '/apps/ctrlPage/saveData', type : 'POST', data : formData, // 告诉jQuery不要去处理发送的数据 processData : false, // 告诉jQuery不要去设置Content-Type请求头 contentType : false, error : function(error){alert("系统错误.")}, success : function(result) { if (result) { $("#showArea").html(JSON.stringify(result)); } } }); } </script> </html>