From Jquery back into Server Side VFP

Topics: Developer Forum
Jul 27, 2013 at 9:48 AM
Please point me to the docs to read to send data from my application back into a rest service -- or Back into FoxPro from a JQuery mobile app.

Does anybody have a simple example. I think I have Pulling data figured out enough, now I have to update the data once somebody changes things on the mobile device.

Thanks
Mike
Coordinator
Jul 27, 2013 at 5:42 PM
Did you look at the source code for the VFP Controller or any of the scripts in the included demo???

Here's a link for you:

http://68.100.149.95:444/avfp6/showhtmlsource?file=customers

You're going to have to learn a little web programming. By the sound of it, this is all new to you.
Jul 27, 2013 at 5:53 PM
I had to hand code everything with json= because the json serialization doesn't work and produce compatible json code. It fails
in web sites that test json. Not very much fun to hand code database conversions one by one.

Its far from done. Typed for about 7 hours yesterday just on one database.

Would have been done a lot faster if I could have gotten the syntax perfect the first around.

Now that I think about it, probably should have parsed it, then ran it back through some cleanup code to get out
what I don't need.

A nightmare.
Coordinator
Jul 27, 2013 at 6:18 PM
abigdreamer wrote:
I had to hand code everything with json= because the json serialization doesn't work and produce compatible json code. It fails
in web sites that test json. Not very much fun to hand code database conversions one by one.

Its far from done. Typed for about 7 hours yesterday just on one database.

Would have been done a lot faster if I could have gotten the syntax perfect the first around.

Now that I think about it, probably should have parsed it, then ran it back through some cleanup code to get out
what I don't need.

A nightmare.
What's a nightmare?

If you think whining that something is not working to your specifications is going to force me to fix something so you can run your little test, you are just not thinking too clearly. If there is a problem you can alert us to it and IF YOU ARE COURTEOUS we may work on it. Ideally, since you claim you're a programmer, you will do at least some of the initial work...
Jul 27, 2013 at 6:50 PM
Parse error on line 105:
... } ] }}True
--------------------^
Expecting 'EOF', '}', ',', ']'

my string.


{"master":{"rows":[{"aaacallnum":"","aaamemtype":"","amount":"345","area":"","billtoact":"COD","billtoaddr1":"435 W THORN ST","billtoaddr2":"","billtocity":"SAN DIEGO","billtocont":"","billtoname":"LAUREN STONE","billtophone":"","billtost":"CA","billtozip":"92103-","bodytype":"2 Door Hatch","callactnum_a":"CPD","callactnum_b":"CPD","callname":"CARLSBAD POLICE DEPARTMENT","callphone":"(760)931-2100","callremark1":"","calltype":"S","colorcar":"BLU","condition":"TOWABLE","cross_street":"","custnum":"COD","datein":"12/31/11","dateout":"01/02/12","datepaid":"01/02/12","days":"3","dispnum":"465971","driver":"JIMMY 19","equipment":"","foxtow_id":"","ftiresize":"","holdnote":"NO RELEASE NEEDED","invdate":"01/02/12","invoicenum":"578737","itemgroup":"C","keysinfo":"N","kitnum":"","licensenum":"6LFM179","licensest":"CA","liendin":"0000-00-00T00:00:00-08:00","liendout":"0000-00-00T00:00:00-08:00","lienfee":"0","lientype":"R","lientypems":"","makecar":"Honda","mapcord":"","membernum":"","miles":"0","milesto":"0","modelcar":"Civic","odometer":"148303","oldinvnum":"","paytype_a":"CRD","paytype_b":"CRD","perday":"45","perdaytotal":"135","ponumber":"","priority":"1","referencenum":"4789230001046624 01/14","refnumber":"11-07961","regaddr1":"3042 BROADWAY","regaddr2":"","regaddr3":"","regcity":"SAN DIEGO","regname":"","regnametow":"ARTHUR ASHLEY","regstate":"CA","regzip":"92102","releasedate":"/ /","releaselic":"E3266266","releasetype":"","release_bywho":"MARIE","release_time":"14:27","release_time2":"14:26","retowto":"","rtiresize":"","storagetype":"3","tagmonthyear":"05/12","timeardst":"23:51","timearrive":"23:18","timecall":":","timeclear":"23:58","timeinrt":"23:07","timeintow":"23:33","timerec":"23:06","towdate":"12/31/11","towedfrom":"2560 EL CAMINO REAL, CBD [@ VONS","towedto":"3199 TYLER STREET, CARLSBAD, CA 92008","towtagnum":"","trucknum":"21","type":"C","vin":"2HGEH2359RH516532","whocalled":"","wposition":"","yearcar":"94"}]}}True
Jul 27, 2013 at 6:52 PM
Edited Jul 27, 2013 at 6:53 PM
Claude its not working PERIOD
run the code through a JSON web site.

it has nothing to do with My specifications
I did not invent JSON
Coordinator
Jul 27, 2013 at 6:59 PM
Edited Jul 27, 2013 at 7:00 PM
It works with this, this and this:

http://68.100.149.95:444/avfp6/jqGrid.avfp

http://68.100.149.95:444/avfp6/JQmobile.html

http://68.100.149.95:444/avfp6/zipsearch.avfp

Why? And if it doesn't work with yours, why not look at the code(https://activevfp.codeplex.com/SourceControl/latest#avfp6.03_source/prg/json.prg) and figure out what it should do and explain it to us how it should be fixed (what line of the code, etc)? Not just that it doesn't work for you... That way you'll learn and help everybody else...
Jul 27, 2013 at 7:05 PM
that string came from Activevfp CODE Claude
The same code that your examples are using that output a table into json.

And since I'm not a programmer I'm not capable of fixing json.prg
Coordinator
Jul 27, 2013 at 7:15 PM
Edited Jul 27, 2013 at 7:15 PM
It's open source, man - YOU CAN WORK WITH THE ACTIVEVFP code. I honestly though everyone understood the meaning of open source - I guess I was wrong.

Others have done it and made important contributions.


The demo code is NOT IN THE activevfp.dll. I'm not sure you understand that either. That code is simply VFP code in good ol' PRGs and avfp text files. Anybody with NotePad can edit that. How did you change the one example you said you got working???
Jul 27, 2013 at 7:22 PM
I paid somebody $150.00 an hour, they are holding my hand this very minute.

I've been outlining my appery.io using Activevfp on this forum and on appery forum and even
in VFP facebook page.

I am contributing.

I know what open source is. But usually important functions like json parsing work
and its not expected to rewrite it.
Coordinator
Jul 27, 2013 at 7:27 PM
Just help and contribute, not rewrite, not complain about everything...
Jul 27, 2013 at 8:40 PM
I pasted your JSON to this site: http://jsonlint.com/

and got the same thing - removing the "True" helps.
Jul 27, 2013 at 8:47 PM
Is there a flag to remove the TRUE? The json came from Activevfp
I didn't find a flag but I didn't read every line of the json.prg

I probably should just reparse the json coming back from the function and remove the true manually.
Coordinator
Jul 27, 2013 at 10:23 PM
Edited Jul 28, 2013 at 12:19 AM
Markmxlxx wrote:
I pasted your JSON to this site: http://jsonlint.com/

and got the same thing - removing the "True" helps.
That's the kind of info that helps.



And something I should be able to fix fairly easily by simply modifying the json.prg. Thanks!
Jul 28, 2013 at 4:22 AM
Where is the json.prg code at? is it inside a class? I'm trying to find it so I can try to take the True out at the end of the line.
strtran() isn't working because its part of oresponse. and string functions don't seem to work there.

Here is the code that makes the json
at the very end we have a 'True' which throws it off.

I tried setting step here, and activating trace but that's turned off it appears.
oJSON.keyforcursors="master"

* send JSON data and properties back
oResponse.ContentType = "application/json;charset=utf-8"  
oResponse.Write(oJSON.stringify('SearchResults'))

oResponse.Flush
lcHTMLout=[]  
Jul 28, 2013 at 4:46 AM
http://www.w3schools.com/asp/asp_ref_response.asp

I found code that explains response .. I guess its ASP
that doesn't tell me why strtran() or some other function doesn't let me manipulate the value.
Jul 28, 2013 at 5:03 AM
This is all obvious to everybody else, but not to me.
Where is the EXE for Activevfp?

There isn't an .app
I found the json.prg inside the Source
The main program is proxystub for source
I don't see a proxystub.exe

I have Activevfp up on my screen
I can build a project and moditfy the json.prg fixing the True problem but
Where do I put things?
Coordinator
Jul 28, 2013 at 8:53 AM
We use a VFP mtdll instead of a VFP exe - works a lot better on the web that way.

json.prg is the json class that Craig Boyd did. It has modifications from me and some others (in the notes in the source). This prg/class is in the ActiveVFP project that is compiled into a VFP mtdll - the activevfp.dll.

To change the source for activevfp.dll, you need to:

1.) Download regular ActiveVFP.
2.) Download the source for ActiveVFP into the directory where regular ActiveVFP is.
3.) Bring up the ActiveVFP project in the VFP IDE.
4.) Make the change to the source.
5.) Compile to an MTDLL



This seems like a really simple problem (the TRUE at the end of the JSON string) so I'm gonna take a look and see if we can get a quick fix.
Jul 28, 2013 at 9:20 AM
That would be great if you could remove the True.

Never made a MTDLL. I did find another Parser made by somebody else but I haven't figured it out yet.
Coordinator
Jul 28, 2013 at 4:48 PM
Well Craig's JSON class is blameless: if you run it separately to a string or just in VFP, you'll see there is NO TRUE on the end. It's got something to do with the way I'm outputting it.
Coordinator
Jul 28, 2013 at 5:04 PM
Edited Jul 28, 2013 at 5:23 PM
Fixed! Return a [] at the end. AVFP expects some sort of RETURN at the end - can just be an empty string.

Try http://68.100.149.95:444/avfp6/customers/getemployees now.


Replace GetEmployees in the Customer Controller with this code:
 PROCEDURE getemployees      && custom method
  
    oJSON=NEWOBJECT('json','json.prg')
    
       SET PATH TO oProp.AppStartPath+'data\AVFPdemo41\'
    
    select e.emp_id as id, e.first_Name as firstName, e.last_Name as lastName, e.title as title, [images/Emps/]+e.picture as picture,count(r.emp_id) as reportCount ;
    from employee e left join employee r on VAL(r.reports_to) = VAL(e.emp_id) ;
    INTO Cursor SearchResults;
    group by e.last_Name,e.emp_id, e.first_Name,e.title, e.picture ;
    order by e.last_Name,e.first_Name
  

    oJSON.keyforcursors="items"

* send JSON data and properties back
    oResponse.ContentType = "application/json;charset=utf-8"  
    oResponse.Write(oJSON.stringify('SearchResults'))
    oResponse.Flush
        RETURN []
 ENDPROC

Jul 28, 2013 at 5:34 PM
That's awesome! thank you. I will try it tonight