【问题标题】:URL With Jquery Mobile带有 Jquery Mobile 的 URL
【发布时间】:2011-08-10 09:08:35
【问题描述】:
 <!-- this is my conexion.html -->


<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js">      </script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.js"></script>

 </head>


<body>


<!-- call ajax page -->
<div data-role="page" id="callAjaxPage">
    <div data-role="header">
        <h1>Connexion</h1>
        <a href="index.html" data-icon="home" data-iconpos="notext"  class="ui-btn-right jqm-home">Home</a>
    </div>

    <div data-role="content">
        <div data-role="collapsible" data-collapsed="false">
                <h3>Sign in</h3>
        <form id="callAjaxForm" method="post" action="conexion.php">
            <div data-role="fieldcontain">
                <label for="email">Email</label>
                <input type="text" name="email" id="email"  />

                <label for="password">Password</label>
                <input type="password" name="password" id="password"  />
                <h3 id="notification"></h3>
                <button data-theme="b" id="submit" type="submit">Go</button>
            </div>
        </form>

        </div>
        <div data-role="collapsible" data-collapsed="true">
            <h3>Create an account </h3>
        </div>
    </div>

    <div data-role="footer">
        <h1>Pied de page</h1>
    </div>
</div>
</body>
   </html>

  <!--- this is my conexion.php -->

    <?php

include('config.php');// connexion to mysql

$email = $_POST['email'];
$password = $_POST['password'];
$request=mysql_query("select * from utilisateur where nom='$email' and password='$password'");
$count=mysql_num_rows($request);
if ($count==0){
    echo "User not found";
}
else echo "Utilisateur founded";

 ?>

【问题讨论】:

    标签: url jquery-plugins jquery jquery-mobile


    【解决方案1】:

    jQuery mobile 将enhance forms with ajax by default(您不必手动为其编写 ajax)。

    尝试将表单的操作设置为处理程序 php 文件,然后让 jQuery mobile 完成剩下的工作。例如:

    <form method="post" action="conexion.php">
        ...
        <input type="submit" />
    </form>
    

    让我们知道你的进展!

    编辑: 根据 cmets 中的讨论,您还需要在 conexion.php 文件中添加一些输出。

    我还建议在将任何用户输入添加到 SQL 查询之前转义它(为了安全起见)。例如:

    <?php
        // conexion.php
    
        include('config.php');// connexion to mysql
    
        $email = $_POST['email'];
        $password = $_POST['password'];
    
        // Escape user input (unless magic quotes has done it already)
        if (!get_magic_quotes_gpc()) {
            $email = mysql_real_escape_string($email);
            $password = mysql_real_escape_string($password);
        }
    
        $request=mysql_query(sprintf(
            "select * from utilisateur where nom='%s' and password='%s'",
            $email,
            $password
        ));
        $count = mysql_num_rows($request);
    
    
    ?>
    <div data-role="page">
        <?php
            if ($count==0){
                echo "<p>Username or password invalid.</p>";
            } else {
                echo "<p>You're in! <a href=\"secure-home.php\">Continue to the app</a>.</p>";
            }
        ?>
    </div>
    

    【讨论】:

    • 所以我可以删除这个? $.ajax({ type: "POST", url: "conexion.php", cache: false, data: formData, success: onSuccess, error: onError });
    • 应该可以,是的。您不应该需要整个脚本块。怎么样?
    • 当我这样做时,出现“未定义”错误,因为“conexion.php”没有收到电子邮件和密码值
    • 您使用的是哪个版本的 jQuery Mobile?是JS还是PHP中的未定义错误?
    • 我正在使用 Beta 2,我认为问题在于每次更改的 URL,因为当我输入 data-ajax="false" 时它可以工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多