Jquery手机登录和访问/拒绝页面


jquery mobile logging in and accessing/rejecting page

我知道这个网站并没有要求人们在特定的代码上工作,但是我很难找到关于jquery移动登录的示例/教程。我不确定如果我这样做是对的,但我试图让用户登录基于mysql数据库(如果用户是在我的数据库),但我试图找出什么写当用户登录?我如何设置,使它将重定向到主页?

PHP page

 if(isset($_POST['email']) && isset($_POST['pass'])){
    $email = mysql_real_escape_string($_POST['email']);
    $password = md5(mysql_real_escape_string($_POST['email']));
    $sql = mysql_query("SELECT password,email FROM users WHERE email = ".$email." AND password = ".$password." LIMIT 1");
}

index . html

   $('form#login').submit(function(){
      var email = $("form#login input.email").val();
      var pass = $("form#login input.pass").val();
           $.post("ajax/post_login.php", {email: email, pass: pass},
               function(data){
               alert("failed"); //if not logged in
               });
    });

我这里有麻烦吗?

有人可以帮助我与jquery移动?

我有不同的许多<div data-role="page">(content here)</div>,我想知道如何访问某个页面,登录时?如果电子邮件/用户名失败,有一个错误?

我很感激你的帮助!谢谢你!

我通过使用自定义AJAX将登录数据发布到服务器并让服务器响应包含采取适当操作所需数据的JSON对象来解决这个问题。

脚本看起来像这样(使用jQuery):

formHandling.formSubmit = function (event, form) {      
    $.post(form.attr("action"), form.serialize(), function (result) {           
        var response = result,
            redirectUrl;
        //Redirect is set, we prio this.
        if (response.Redirect) {
            redirectUrl = response.Redirect;
            //Default redirect can be overridden by querystring
            if (helpers.getParameterByName("redir") !== "") {
                redirectUrl = helpers.getParameterByName("redir");
            }
            document.location.href = redirectUrl; //This will cause a "full page load", but is desired in order to clean out the "Logged out view" of the pages
        } else if (response.Result) { //If no redirect is set, display the result in the target
            var resultTargetId = form.attr("data-result-target-id");
            formHandling.displayResult(resultTargetId, response.Result); //Displays an error/success message in element with id = resultTargetId
        }
    });
    event.preventDefault();
};

和从服务器端返回的JSON数据示例:

//Failed login
{
    Redirect: null, 
    Result: {
        IsError: true,
        ErrorMessage: "Failed to login" 
    }
}
//Successful login
{
    Redirect: "http://www.example.com/someloggedinpage",    
    Result: {
        IsError: false,
        ErrorMessage: ""    
    }
}