<pre></pre>
I'm newbie to PhoneGap, have done some research before starting on development. I have registered through the website site to test app, so I need to test with my credentials and see if can will login. I do get the string from server which contains sessionid and name of person login in. So I need to save that in cookies, of which
phonegap do not support the saving of data in cookies so need to store it in localStorage to now if user is login or logout.
I'm using html5, CSS and javascript.
My html code
<pre><form id="goin" name="goin" class="goin" onclick="Goin()" >
<h3>Sign In</h3>
<input type="email" name="email" id="email" required="required" class="email" value="" Placeholder="Email Address" >
<input type="password" name="password" id="password" class="password" required="required" value="" placeholder="Password" >
<input type="submit" id="login" name="login" class="login" value="Login"><br/>
<div class="noaccount">
<b>No account?</b><a href="register.html">Sign Up</a>
</div>
</form>
String that I get is in this format
43330KDDD|Name|
So I need to store that in local storage
As
Session with its
value
Name with the
value
<pre><pre><pre>
Help will be appreciated.
What I have tried:
When I tried to use ajax it gives me the error alert
function Goin() {
var form = $("#goin");
var url = 'https://www.test.login';
var email = $("#email").val();
var password = $("#password").val();
var loginPath = url + 'testlogin?' + email + '|' + password + '|';
if(email != "" && password != "") {
$.ajax({
type: 'POST',
url: loginPath,
crossDomain: true,
data: {email: email, password :password},
dataType: 'json',
async: false,
//if login success store session id in cookie
success: function (response){
console.log('response');
alert ("response");
if (response.success) {
alert("You're logged in");
console.log("You're logged in");
window.localStorage.setItem("sessionId", "value");
var sessionId = window.localStorage.getItem("sessionId");
window.location.replace("index.html");
}
else {
//alert("Your login failed");
console.log('Your login failed');
window.location("signin.html");
}
},
error: function(error){
//alert(response.success);
console.log('Could not connect to the server');
alert('Could not connect to the server' + error);
window.location = "signin.html";
}
});
}
else {
//if the email and password is empty
console.log('You must enter email and password')
alert("You must enter email and password");
}
return false;
}