Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Regular Contributor
Posts: 89
Registered: ‎10-27-2010
My Device: Passport SQW100-1
My Carrier: Meteor
Accepted Solution

JSON login script from jqm to bbui help needed

[ Edited ]

Hello,

 

A few months ago i tried to start with bbui to get more native objects (like swipe down menu).

The problem is that bbui sucks compare to jqm (kitchensink) my complete app depends on it, and the part i'm now is logging in and registering a new user from the app.

 

This is an example code i use a lot:

 

Form example

[code]

<form id="JqAjaxForm"> 

<input name="email" type="text" id="email" data-theme="a" placeholder="Username"  required="required"/>

<input type="password" id="password" name="password" placeholder="Password" data-theme="a" required="required"/>

<input type="submit" data-theme="a" name="submit" value="Sign in"/>

</form>

[/code]

 

Jquery example:

[code]

$(function(){
$("#JqAjaxForm").submit(function(e){

var b=document.forms["JqAjaxForm"]["email"].value;
var c=document.forms["JqAjaxForm"]["password"].value;

dataString = $("#JqAjaxForm").serialize();

 

$.ajax({
type: "POST",
url: "http://myserver.com/login.php",
data&colon; dataString,
dataType: "json",
success: function(data)
{

 

if (data.usrkey == "undefined") { alert("User / Password incorrect");
} else if (data.usrkey == "null") { alert("User / Password incorrect");
} else if (data.usrkey == "0") { alert("User / Password incorrect");
} else if (data.banned == "1") { alert("User / Password incorrect");
}
else
{

usrid = data.usrid;

var usrid = data.usrid;

localStorage.setItem('userd', usrid);

 

 window.location.assign("start.html");

}

 

}

});

});
});

[/code]

 

what the code does, if the json data in login.php is 0 or undefined it means your user/pass is wrong.

when usr.banned is 1 it means you did something wrong and you are banned from the app Smiley Wink

otherwise it will return your userid and that will always be higher than 0 so you will get a localstorage (aka logged in).

 

 

This code does exactly what is should do... in jquery.

I tried to mix different versions of jquery and jquery mobile together with bbui but it messed up every little thing.

And this json/ajax request does in this case only logging in, but i use it way more.

 

As example get user information, submit information, check if you have access to parts (0/1).

 

 

Anyway to make long a bit shorter, jquery does not work together well with bbui.

So i'm locked out from my app, and cannot register a new user because it uses jquery to submit.

 

 

Does anyone have an good example of the code above that does exactly the same?

but works in bbui, OR a jquery(mobile) lib i can use together with bbui

 

 

 

 

 

Small update from my side, when i use the zepto plugin (http://zeptojs.com/) i get the error below:

 

ReferenceError: Can't find variable: webworks

 

 

This error i will also get when i include any jquery or jqm javascript file

Developer
Posts: 1,229
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C
My Carrier: 3, Orange, Vodafone

Re: JSON login script from jqm to bbui help needed

Youmneed to instantiate WW in the onload

 

e.g. (gimme a sec to Cut + Paste)

webworksreadyFired = false;

window.addEventListener('load',function() { document.addEventListener('webworksready', function(e) { if (webworksreadyFired) return; webworksreadyFired = true;
// Do something }
}

 Soz this is a bit rough - there are a lot more things to handle at this stage but that's the basics




Click the like button if you find my posts useful!
Highlighted
Regular Contributor
Posts: 89
Registered: ‎10-27-2010
My Device: Passport SQW100-1
My Carrier: Meteor

Re: JSON login script from jqm to bbui help needed

i forgot to mention indeed that i already have those around it.

my login script is working now, jquery 1.9x was the problem, no issues with 1.8.x