javascript - Simple login system for PhoneGap app - Stack Overflow

I'm trying to build a simple login system for my PhoneGap app. I have a form where user gives a us

I'm trying to build a simple login system for my PhoneGap app. I have a form where user gives a username and if there is a matching username in the MYSQL the user is redirected to another page. Else an alert is shown. The code works just fine on firefox and chrome, but when I try to use it on Safari or on the PhoneGap app it doesn't seem to work. What could be the reason?

HTML

    <form id="login-form" rel="external" data-ajax="false" >

    <label for="number">Number:</label> 
    <br>
    <input type='tel' name="number" id="number" data-corners="false" data-theme="d"/>
    <br>

    <label for="username">Username:</label>
    <br>

    <input name="username" id="username" data-corners="false" data-theme="d"/>
    <br>

<input type="submit" value="OK" data-theme="b" data-corners="false" />
</form>

JS

 $(function() {    
     $('#login-form').submit(function(event) {
         event.preventDefault();

         $.post(serviceURL +'login.php', { 
             kayttaja: $('[name="username"]').val(), 
         }).success(function(data) { 
             if (data.status == 'ok') {
                 var input = document.getElementById("number");
                 var user = document.getElementById("username");
                localStorage.setItem("number", input.value);
                localStorage.setItem("username", user.value);
                 window.location.pathname = data.redirect;
             } else {
                 alert(data.message);
             }
         })
     })
}) 

I'm trying to build a simple login system for my PhoneGap app. I have a form where user gives a username and if there is a matching username in the MYSQL the user is redirected to another page. Else an alert is shown. The code works just fine on firefox and chrome, but when I try to use it on Safari or on the PhoneGap app it doesn't seem to work. What could be the reason?

HTML

    <form id="login-form" rel="external" data-ajax="false" >

    <label for="number">Number:</label> 
    <br>
    <input type='tel' name="number" id="number" data-corners="false" data-theme="d"/>
    <br>

    <label for="username">Username:</label>
    <br>

    <input name="username" id="username" data-corners="false" data-theme="d"/>
    <br>

<input type="submit" value="OK" data-theme="b" data-corners="false" />
</form>

JS

 $(function() {    
     $('#login-form').submit(function(event) {
         event.preventDefault();

         $.post(serviceURL +'login.php', { 
             kayttaja: $('[name="username"]').val(), 
         }).success(function(data) { 
             if (data.status == 'ok') {
                 var input = document.getElementById("number");
                 var user = document.getElementById("username");
                localStorage.setItem("number", input.value);
                localStorage.setItem("username", user.value);
                 window.location.pathname = data.redirect;
             } else {
                 alert(data.message);
             }
         })
     })
}) 
Share Improve this question asked Jun 6, 2012 at 9:50 user1323294user1323294 6325 gold badges15 silver badges23 bronze badges 2
  • which version of phonegap are you using?? If its cordova then check whether you have included the server in <access origin=''> list – dhaval Commented Jun 6, 2012 at 10:56
  • I'm using cordova, and i have set <access origin=".*"/> – user1323294 Commented Jun 6, 2012 at 11:08
Add a ment  | 

1 Answer 1

Reset to default 2

you can follow these steps for creating simple login system using phonegap / apache cordova

  • Create JSON based Web Service for Authentication Purpose
  • Use JQuery / Angular JS for Connect with Web Service using Ajax method
  • If authentication success, redirect page using javascript window.location.href="home.html"
  • use localStorage for Storing auth values

I got this information from https://codesundar./phonegap-login-system-using-php-mysql/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745307154a4621780.html

相关推荐

  • javascript - Simple login system for PhoneGap app - Stack Overflow

    I'm trying to build a simple login system for my PhoneGap app. I have a form where user gives a us

    10小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信