最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

解決ajax返回驗(yàn)證的時(shí)候總是彈出error錯(cuò)誤的方法

 更新時(shí)間:2016年01月06日 15:50:55   作者:沒有夢(mèng)想-何必遠(yuǎn)方  
這篇文章主要介紹了解決ajax返回驗(yàn)證的時(shí)候總是彈出error錯(cuò)誤的方法,感興趣的小伙伴們可以參考一下

發(fā)一個(gè)簡(jiǎn)單案例:
前臺(tái):

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
 <head> 
   <title>用戶登錄</title> 
   <script type="text/javascript" src="../js/jquery-easyui-1.3.5/jquery.min.js"></script> 
   <script type="text/javascript" src="../js/jquery-easyui-1.3.5/jquery.easyui.min.js"></script> 
   <link rel="stylesheet" href="../js/jquery-easyui-1.3.5/themes/default/easyui.css" type="text/css"></link> 
   <link rel="stylesheet" href="../js/jquery-easyui-1.3.5/themes/icon.css" type="text/css"></link> 
   <script type="text/javascript" src="../js/jquery-easyui-1.3.5/locale/easyui-lang-zh_CN.js"></script> 
   <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> 
   <script type = "text/javascript" charset = "UTF-8"> 
   $(function(){ 
     var loginDialog; 
     loginDialog = $('#loginDialog').dialog({ 
       closable : false , // 組件添加屬性:讓關(guān)閉按鈕消失 
       //modal : true, //模式化窗口 
       buttons : [{ 
         text:'注冊(cè)', 
         handler:function(){ 
            
         } 
       }, 
       { 
         text:'登錄', 
         handler:function(){ 
            $.ajax({ 
             url:'../servlet/Login_Do', 
             data :{ 
                name:$('#loginForm input[name=name]').val(), 
                password:$('#loginForm input[name=password]').val() 
               }, 
             dataType:'json', 
             success:function(r){ 
              //var dataObj=eval("("+data+")"); 
               alert("進(jìn)來了"); 
             }, 
             error:function(){ 
               alert("失敗"); 
             }   
              
           }); 
            //alert(data) 
         } 
       }] 
     }); 
   }); 
   </script>  
 </head> 
 <body style=”width:100%;height:100%;" > 
    <div id = "loginDialog" title = "用戶登錄" style = "width:250px;height:250px;" > 
      <form id = "loginForm" method = "post"> 
        <table> 
        <tr> 
          <th>用戶名 :</th> 
          <td><input type = "text" class = "easyui-validatebox" data-options="required:true" name = "name"><br></td> 
        </tr> 
        <tr> 
          <th>密碼: </th> 
          <td> <input type = "password" class = "easyui-validatebox" data-options="required:true" name = "password"><br></td></td> 
        </tr> 
        </table> 
      </form>  
    </div> 
 </body> 
</html> 

 后臺(tái):

public class Login_Do extends HttpServlet { 
  public void doGet(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException { 
      this.doPost(request, response); 
  } 
  public void doPost(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException { 
    request.setCharacterEncoding("UTF-8");  
    response.setCharacterEncoding("UTF-8"); 
    String name =request.getParameter("name"); 
    String password = request.getParameter("password"); 
    String js = "{\"name\":name,\"password\":password}"; 
    PrintWriter out = response.getWriter(); 
    JSONObject json = new JSONObject(); 
    json.put("name",name); 
    out.print(json.toString()); 
    response.getWriter().write(json.toString()); 
  } 
}

 點(diǎn)擊登錄時(shí):

解決辦法:彈出error信息一般有兩種可能:
第一種:url錯(cuò)誤,后臺(tái)直接得不到值
可以用火狐的firebug查看:如果響應(yīng)了信息,則不是這個(gè)問題,那么就有可能是第二種情況
返回?cái)?shù)據(jù)類型錯(cuò)誤:
在我這個(gè)例子中,返回的數(shù)據(jù)無意中打印了兩次,這兩句刪去一句就好了:

out.print(json.toString()); 
response.getWriter().write(json.toString());  

造成了錯(cuò)誤。這時(shí)在firebug顯示的信息是:

以上就是為大家分析的用ajax返回驗(yàn)證的時(shí)候總是彈出error的原因,希望對(duì)大家解決此類問題有所幫助。

相關(guān)文章

最新評(píng)論

江城| 凤城市| 清徐县| 敦化市| 诸暨市| 西峡县| 宝鸡市| 莎车县| 左权县| 昭苏县| 平武县| 灵川县| 灵川县| 大兴区| 囊谦县| 云林县| 黎川县| 恭城| 内乡县| 南投市| 安远县| 长泰县| 吉木乃县| 宜黄县| 舟曲县| 东辽县| 罗田县| 读书| 北海市| 林周县| 铁岭县| 石首市| 四会市| 眉山市| 芒康县| 和硕县| 津市市| 赣州市| 雅安市| 鹰潭市| 龙里县|