1***@qq.com
1***@qq.com
  • 发布:2017-04-19 11:16
  • 更新:2019-12-16 11:44
  • 阅读:1403

前台接收不了返回的json

分类:HBuilder

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script src = "js/exif.js" ></script >
<script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp&key=IOJBZ-K3BKV-UIZPP-USAM7-HEUKJ-XBFMR"></script>
<script type="text/javascript" src="https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js"></script>
<script src="js/comjs/dist/jquery-1.11.2.min.js"></script>
<script src="js/comjs/jquery-1.6.1.js"></script>
<script src="js/comjs/dist/lrz.bundle.js"></script>
<title>test</title>
</head>

<body>

<div data-role="header"><h1>test</h1></div>

<div data-role="content" class="content">
<p style="backg"><font color="#2EB1E8" >登录</font></p>
<form action="http://192.168.1.24:8080/bk/person.do?method=login" method="post" id="loginform">
<input type="text" name="account" id="account" value=""/><br>
<input type="password" name="password" id="password" value=""/>
<fieldset data-role="controlgroup" >
<input type="checkbox" name="checkbox-1" id="checkbox-1" class="custom" />
<label for="checkbox-1">保持登录状态</label>
</fieldset>
</form>
</div>
<input type="button" onclick="getSignedAmount()" value="登陆">

<div data-role="footer" ><h1>test</h1></div>
<!-- end first page -->
<script>
function getSignedAmount(){
alert("1111");

$.ajax({    
                    url : "http://localhost:8080/bk/appJson/Output.jsp",    
                    type: "POST",    
                    data : {    
                        imgdata:"1",  
                        perid:"1",  
                        pictime:"1"  
                        //压缩后的base值    
                    },  //要发送的数据  
                    dataType:"json",  //返回的数据格式  
                    cache:false,    
                    async:false,    

                    success : function(data) {    
                        alert("33333:"+data);   
                        var dataRole =$.parseJSON(data);  
                    alert("33333:"+data);   
                        if(data.flag==0)    
                            {    
                                var filetemp = document.getElementById(inputid).value ;  
                            }else{    
                                alert(data.mes);///data.message为上传失败原因    
                            }    
                   },    
                    error : function(err){    
                            alert("上传失败:"+displayProp(err));    
                    }    
                 });   

}
function displayProp(obj){
var names="";
for(var name in obj){
names+=name+": "+obj[name]+", ";
}
alert(names);
}
</script>
</body>

Output.jsp
<%
response.setContentType("text/json;charset=utf-8");
response.setContentType("text/json");
response.setCharacterEncoding("gb2312");
JSONObject json = new JSONObject();
json.put("flag",0);
json.put("mes","上传成功!");
PrintWriter pw = response.getWriter();
pw.print(json.toString());
pw.close();
%>

运行后
一直都是走到 error 这里 是什么问题啊?求大神指教!谢谢!

2017-04-19 11:16 负责人:无 分享
已邀请:
菜鸟PHP

菜鸟PHP

ajax返回的不是正确的json 格式 或者 有错误,把返回类型json 注释掉,打印ajax返回值

5***@qq.com

5***@qq.com

请问楼主,这个问题有解决吗?

该问题目前已经被锁定, 无法添加新回复