The, would allow the user to get into the app otherwise no.
The link to my json database that I'm using here as a login tool is (https://www.jasonbase.com/things/2w8M.json
I'm getting problem on setting the response as variable because it contains lines.
Here is RAW source code of my app is attached. Please suggest changes especially in var Json.
Thanks in Advance, droidscript team, you people are working very hard for use without any Return. Hats of to you
App source code
// password= 2w8M.
//Called when application is started.
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
//Create a button to get Login.
btn = app.CreateButton( "Login", 0.3, 0.1 );
btn.SetOnTouch( btn_OnTouch );
lay.AddChild( btn );
txt=app.CreateTextEdit(1,0.5);
lay.AddChild(txt );
//Add layout to app.
app.AddLayout( lay );
}
//Handle button press.
function btn_OnTouch()
{
//Send request to remote server.
var pw= txt.GetText();
url = "https://www.jasonbase.com/things/"+pw+".json"
SendRequest( url );
}
//Send an http get request.
function SendRequest( url )
{
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() { HandleReply(httpRequest); };
httpRequest.open("GET", url, true);
httpRequest.send(null);
app.ShowProgress( "Loading..." );
}
//Handle the server's reply (a json object).
function HandleReply( httpRequest )
{
if( httpRequest.readyState==4 )
{
//If we got a valid response.
if( httpRequest.status==200 )
{
message = httpRequest.responseText;
var json = message;
}
if(json= "{
"User":"OK"
}")
{
app.LoadScript("SMS.js" );
}
//An error occurred
else
app.Alert( "Error: " + httpRequest.status + httpRequest.responseText);
}
app.HideProgress();
}
if(json= "{
"User":"OK"
}")
This would never work in code, because strings have to be defined in one line. When the line ends but the string doesn't js would detect it as mistake.
You can use escaping sequences for that. a linebreak is simply a "\n". Or "\r\n" for Windows.
The second problem are the quotes in your string. You can't just type "Quotes "in" string" - the - 'in' would be detected as outside of the strings.
You should escape them as well to tell js to don't interpret them as special characters. Result would be "Quotes \"in\" string".
Instead you could also use single quotes - they're also interpreted as strings - so 'Quotes "in" string' would work as well.
The third problem - you're using a single '=' This is an assign operator. So you'll assign json to the string instead og comparing it (what is probably what you want) Use '==' for comparing two values.
The last thing: you don't have to check the string.
You can easily run into problems when doing so (maybe you missed a space or using \r\n instead of \n or whatever. To prevent all this you should use the builtin JSON object.
Use JSON.parse(string) to get the json object from a string, or JSON.stringify(obj) to generate the string from a json object.
Then you cam simply check the data using
JSON.parse(httpRequest.responseText).User == "Ok"
You can also convert it here to lower case to prevent upper-lower case issues using User.toLowerCase(). To be very sure you can also use User.trim() additionally to remove whitespace at the beginning and the end of a string.
Does this help you with your problem?