簡體   English   中英

使用Jquerymobile,Ajax和PHP使用Webservice(登錄)

[英]Consuming webservice using Jquerymobile, Ajax and PHP (Login)

我已使用mySQL在Jelastic上創建了一個數據庫,而Jelastic不允許在該數據庫上托管php頁面,因此我創建了一個Web服務來幫助我。 我目前將我的login.php托管在本地。 Web服務有一個名為,getCustomQuery功能,但我使用Web服務試圖在目前不同的方法來繞過希望。

好的,這是我的index.html頁面

<!DOCTYPE html>
<html>
    <head>
    <title>Submit a form via AJAX</title>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4/jquery.mobile-1.0a4.min.css" />
    <script src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.0a4/jquery.mobile-1.0a4.min.js">     <script>
</head>
<body>
    <script>
       function onSuccess(data, status)
       {
           data = $.trim(data);
           $("#notification").text(data + " Success");
       }

       function onError(data, status)
       {
           $("#notification").text(data+ " " + status);
       }        

       $(document).ready(function() {
           $("#submit").click(function(){

               var formData = $("#callAjaxForm").serialize();

               $.ajax({
                   type: "POST",
                   url: "login.php",
                   cache: false,
                   dataType: "text",
                   data: formData,
                   success: onSuccess,
                   error: onError
               });

               return false;
           });
       });
   </script>

   <!-- call ajax page -->
   <div data-role="page" id="callAjaxPage">
       <div data-role="header">
           <h1>Call Ajax</h1>
       </div>

       <div data-role="content">
           <form id="callAjaxForm">
               <div data-role="fieldcontain">
                   <label for="userName">Username</label>
                   <input type="text" name="userName" id="userName" value=""  />

                   <label for="passWord">Password</label>
                   <input type="text" name="passWord" id="passWord" value=""  />
                   <h3 id="notification"> Something here</h3>
                   <button data-theme="b" id="submit" type="submit">Submit</button>
               </div>
           </form>
       </div>


   </div>
</body>
</html>

現在,索引頁面獲取用戶名和密碼,並使用jquery和ajax將其發布到登錄頁面。

<?php

$userName = $_POST[userName];
$passWord = $_POST[passWord];

echo("LastName: " . $userName . " Password: " . $passWord);

$con = mysql_connect("url", "username", "password"); 
if (!$con) {
    die('Could not connect: ' . mysql_error());
}
$passWordMD5 = md5($passWord , false);
mysql_select_db("club_in", $con);

$result = mysql_query("SELECT * FROM user WHERE user_username='+ $userName+' AND user_password='+$passWordMD5+'");

while ($row = mysql_fetch_array($result)) {
    echo $row['user_username'] . " " . $row['user_password'];
    echo "<br />";
}


mysql_close($con);
?>

現在,login.php頁面從index.html頁面獲取傳遞給它的兩個變量。 login.php md5哈希密碼,因為如果數據庫被黑客入侵,所有密碼都將存儲為md5哈希,以幫助提高安全性。 現在,這對我來說有點麻煩了,因為我已經嘗試了SQL查詢並且可以在mySQL中運行,並且當它返回到index.html頁面時,我獲得了成功,但是唯一得到的是php頁面的整個文本。 我只需要login.php頁面應該從數據庫中提取的信息。 你能幫忙嗎? 任何有用的建議將不勝感激。

如果您得到的是php代碼而不是解析結果:

  • Web服務器不知道PHP。 你有一個PHP解析器安裝?
  • Web服務器無法執行腳本。 文件權限是什么? (Linux)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM