struts2.0.11+jquery1.4.4, ajax方式实现登录,为什么firefox下是好的,在IE7下不行?

jlpf 2010-12-23
参考 这个link做了个sample http://www.114java.com/JavaScript_ajax_jquery_flex/2010/0331/1052_2.html



在firefox下工作正常,但在IE7下不成功,没有弹出回调函数中的alert窗口。

java 类
public class LoginSample {

	
	public String userLogin(){
		
	      jsonRoot.put("logeResult",false);
		
	 return "logErro";
		 }
	
	
private Map<String, Object> jsonRoot = new HashMap<String, Object>();
	 
	 public Map<String, Object> getJsonRoot() {
	  return jsonRoot;
	 }
	 public void setJsonRoot(Map<String, Object> jsonRoot) {
	  this.jsonRoot = jsonRoot;
	 }
}


xml
 <package name="sample" namespace="/sample" extends="json-default">				
				
				
				<action name="userLogin" class="com.cmp.action.admin.LoginSample" method="userLogin">           			
           			<result name="logErro" type="json">           			
           			</result>           			 
				</action>		
				
						
     </package>


jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="../jquery/jquery-1.4.4.min.js"></script>
</head>
<body>
<form action="" name="logform" id="logform">
          <div class="wline">username:<input  type="text" name="logUsername" id="logUsername" value="" style="width:120px;"/></div>
          <div class="wline">password:<input  type="text" name="userPassword" id="userPassword" value="" style="width:120px;"/></div>
          <div class="wline">checkcode:<input type="text" id="checkCode" name="checkCode" class="required input" title="checkcode"/>
          </div>
         <div class="wline">
         <input  type="button" name="" value="login" onclick="ajaxlogin();" style="width:50px; height:25px; "/>
         <input  type="button" name="" value="back" style="width:50px; height:25px; "/>
       
          </div>
  </form>
</body>

<script>
function ajaxlogin(){
	  var params=$('#logform').serialize(); //这里直接就序列化了表单里面的值;很方便

	   $.ajax({
	               url :'userLogin.action',  //后台处理程序
	               type:'post',    //数据发送方式
	               dataType:'json',   //接受数据格式
	               data:params,   //要传递的数据;就是上面序列化的值
	               success:login_Result //回传函数(这里是函数名) 
	   });
	     
}
 function login_Result(json){ //回传函数实体,参数为XMLhttpRequest.responseText
	 alert("tset");
	  if(json.logeResult){
   alert("this is 1");
  }else{
   alert("this is 2");
  }
 }

  
	               
</script>
</html>


那位高手知道什么原因?

先行谢过!!
jlpf 2010-12-26
找到原因了,struts.i18n.encoding=utf8, 改成struts.i18n.encoding=UTF-8就好了。
suihr 2010-12-28
感谢分享!
Global site tag (gtag.js) - Google Analytics