简体   繁体   English

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

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

I have created a database on Jelastic with mySQL and Jelastic does not allow php pages be hosted on there, so I have created a web service to help me. 我已使用mySQL在Jelastic上创建了一个数据库,而Jelastic不允许在该数据库上托管php页面,因此我创建了一个Web服务来帮助我。 I currently have my login.php hosted locally. 我目前将我的login.php托管在本地。 The web service has a function called, getCustomQuery, but I'm trying a different approach at the moment to hopefully bypass using the web service. Web服务有一个名为,getCustomQuery功能,但我使用Web服务试图在目前不同的方法来绕过希望。

Okay so this is my index.html page 好的,这是我的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>

Now the index page gets a username and password and posts it to teh login page, using jquery and ajax. 现在,索引页面获取用户名和密码,并使用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);
?>

Now the login.php page gets the two variables passed to it from the index.html page. 现在,login.php页面从index.html页面获取传递给它的两个变量。 The login.php md5 hashes the password, because all passwords are stored as md5 hashes to help a bit with security, if the database gets hacked. login.php md5哈希密码,因为如果数据库被黑客入侵,所有密码都将存储为md5哈希,以帮助提高安全性。 Now this is where things get a little fuzzy for me, since I've tried the SQL query and it works in mySQL and when it returns to the index.html page I get a success, but the only thing that I get back is a the whole text of the php page. 现在,这对我来说有点麻烦了,因为我已经尝试了SQL查询并且可以在mySQL中运行,并且当它返回到index.html页面时,我获得了成功,但是唯一得到的是php页面的整个文本。 I only need the info that the login.php page was suppose to pull from the database. 我只需要login.php页面应该从数据库中提取的信息。 Would you please help? 你能帮忙吗? Any useful suggestions would be greatly appreciated. 任何有用的建议将不胜感激。

if you get the php code instead of the parsed result: 如果您得到的是php代码而不是解析结果:

  • the webserver doesn't know php. Web服务器不知道PHP。 do you have a php parser installed? 你有一个PHP解析器安装?
  • the webserver cannot execute the script. Web服务器无法执行脚本。 what are the file persmissions? 文件权限是什么? (linux) (Linux)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM