Get value from PHP


#1

Good day,
I currently have a form in javascript (Login with username and password)
I POST the captured values with req = Ajax( etc. to a PHP script on a server and validates the the username and password to a sqlserver database.
I get the the req.status back and if 200 I open the app for processing.
My requirement is that in the same req I want to retrieve a specific value and store this value on the phone for retrieval later. I do not want the response (echo) to be displayed. It must immediatly be stored in a cookie of some sorts.
Any such example out there?
Thanks


#2

Have you looked at this Tech Note?

https://wiki.nsbasic.com/Ajax_made_Simple


#3

I have, thank you but do not quite see or understand the solution as it would relate to what I want to do
rgs


#4

Where is it not working for you? Is the information coming back?


#5

I can get the value I want in PHP from the databse. I need an example of how to pass it back to the client (javascript) and then how to receive the value and then to store this variable data on the phone.


#6

Have a look at the samples in the Tech Note I cited. They return values via PHP.

There are also samples.

Are you having trouble getting the information back, or saving it?


#7

Hi, thank you for the responses.
I am making progress.
I now have the following code in javascript:
req = Ajax(“https://ccccccccc/ff.php”, “POST” , “username=” + TextBox1.value + “&password=” + TextBox2.value, done);

function done() {
if (req.status == 200) { //success
TextArea1.value = req.responseText;
etc…
And I am getting the correct value I want back from php
Now, if I want more values, how would I return an array that I can assign multiple variables in javescript?
Thanks


#8

I am by no means an expert with AppStudio, but I have been playing around with returning several values (PHP query to a MySql DB) and I just return the whole lot as a CSV

So when I query a database for a score I receive:

John Doe, Game Name, 305

as an example. I then parse that line or lines that are returned and then deal with them - be it individually or put them into an Array.


#9

Sorry for the delay in getting back
I am almost there.
My status with this is as follows:
JavaScript in NSB appstudio is:

req=Ajax("https://itjustworx.bla/blabla/CheckPWD.php?username=" + TextBox1.value + "&password=" + TextBox2.value, done);

PHP module correctly receives this, I process the results and get a numeric “1” back into javascript which is what I want

function done() {

if (req.status == 200) { //success
var tt = req.responseText;

// tt contains the "1"

Now I want to store this result in localStorage.
I’ve tried both

localStorage.MemberBelongsToID = tt;

AND

localStorage.setitem ("MemberBelongsToID ", tt);

I get error in both methods

code.js

Version:1.0 StartHTML:000000224 EndHTML:000003393 StartFragment:000003249 EndFragment:000003343 StartSelection:000003249 EndSelection:000003343 SourceURL:file:///C:/inetpub/wwwroot/Responseman/Responseman/index.html

Unable to set property 'MemberBelongsToID' of undefined or null reference.
line 13 column 1

#10

What browser are you using?
Are you running in private or incognito mode?

Try typing this into the browser console:

localStorage.test = "ok"

#11

Hi and thank you!
OK, some feedback and then we can close this thread.
After I have completed the app, applying changes as per suggestions, I have been testing my app using the deploy and I ran it in both Internet Explorer and Chrome on the server. In IE the app ran fine but I got the error I described. In Chrome, I dont get the correct response back, at all. However, testing the localstorage as per your lead in the console, it works fine.
However, that all said, I made the app (Native phonegap app) as is the ultimate intent and it is working perfectly!! One last question, is there any other method I can use to test without deploying to the actual device?
Have a good day!
rgs
Zack


#12

There is an official Android Emulator:

https://developer.android.com/studio/run/emulator

however I find it much easier and faster to use an actual device.