自己做了个帝国CMS表单提交,但是form的转跳页面提示,想做成ajax根据返回信息提示。

    ajax提交思路代码:

    var data = $('#form').serialize(),
                                url = $('#form').attr('action');
                    $.ajax({
                            method:"POST",
                            url:url,
                            data:data,
                    }).done(function(){
                            alert("Thank you.");
                            document.getElementById("form").reset();
                    }).fail(function(){
                            alert("Network went wrong, Please try again later.");
                    });

    我一直用这个好久了,缺点就是没有提示信息,当有字段没填时,帝国默认会出来个页面提示有字段未填,用这个不会有提示,并且代码认为提交成功了,真正提交成功不会有问题。

    完整示范如下:

    $.post("/e/member/doaction.php",
    {
    username:username,
    password:password,
    lifetime:lifetime,
    enews:"login", //login
    tobind:"0"
    },
    function(data,status){
            if(data.indexOf("登录成功") >= 0){
                    tishi('登陆成功,页面跳转中..请稍后',2);
            }else if(data.indexOf("您的用户名或密码有误") >= 0){
                    tishi("您的用户名或密码有误");
            }else if(data.indexOf("审核") >= 0){
                  tishi("您的帐号还未通过审核!");
            }else if(data.indexOf("为空") >= 0){
                    tishi("用户名和密码不能为空");
            }else {
                    tishi("登录不成功,请确认您的cookie是否已开启!");
            }
    }
    )