首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

AJAX SSH登陆验证回调函数异常有关问题

2013-07-04 
AJAX SSH登陆验证回调函数错误问题问题精简如下:javascript中:function login(){var urlLogin_loginva

AJAX SSH登陆验证回调函数错误问题
问题精简如下:
javascript中:


function login(){
var url="Login_login";
var params={"id":1,"password":"110"};
//ajax()方法
jQuery.ajax({
            type: "get",
            async: true,
            url: url,
            data: params,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            success: function (data) {
            alert("success "+data.id);
            },
            error: function (err) {
                alert("erro");
            }
        });



struts.xml如下:

 <package name="default" namespace="/" extends="json-default">
        <action name="*_*" class="com.sanxiau.action.{1}Action"
        method="{2}">
            <result type="json" name="success">
<param name="incluepropeties">
result
</param>
            </result>
        </action>
    </package>


action如下:

public class UserLoginAction {
private int id;
private String password;
private boolean isSuccess;
//不用new,用spring容器提供
//private UserService userService=new UserServiceImp();过时
private UserService userService;
private ApplicationContext applicationContext=null;
private String result;
public String login(){
/*测试一下*/
System.out.println("id="+this.getId()+"password="+this.getPassword());

//applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
//userService = (UserService) applicationContext.getBean("UserServiceImpl");
//isSuccess=userService.checkIdAndPassword(id, password);

 Map<String, Comparable> map = new HashMap<String, Comparable>();  
 map.put("id", this.getId());  
         map.put("password",this.getPassword()); 
         JSONObject obj = JSONObject.fromObject(map);
         result = obj.toString();  
         System.out.println("result is "+result); 

return "success";
}



当打开action中注释的那三排就返回执行的就是alert("erro");
不管async: true,还是false!很纠结啊!!
为什么会这样呢,我用firefox调试看到,打开action注释的那三排执行时间就要3s左右,因为访问了数据库,时间耗得多嘛,然而注释掉就600ms左右,难道这跟action中执行的时间有关,
action中测试的均正确,控制台输出的都是json格式的; Ajax SSH 登陆验证
[解决办法]
听的你描述,很可能是因为ajax访问超时了,有参数可以设置的,我记的单位应该是ms.不过你访问下数据库要3秒~~~也蛮牛B了
[解决办法]
引用:
Quote: 引用:

那你直接用url访问这个action的login方法,看看有木有弹出新页面的数据

我刚试了一下,不采用ajax的方式,直接提交,处理后返回的都是正确的值


那你试下不用ajax方法,直接使用$.post("xxxx.action","a=b",function(data){alert(data);});

热点排行