2020.06.30 07:27:04:315 : Server: default routing from time
2020.06.30 07:27:04:317 : Server: Send json response
Which are my output messages.button clicked
URL :http://localhost:9080/time
loaded.....
button clicked
client.js:12458 URL :http://localhost:9080/time
client.js:12458 loaded.....
client.html:1 Access to XMLHttpRequest at 'http://localhost:9080/time' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
The browser console showed me:Code: [Select]button clicked
client.js:12458 URL :http://localhost:9080/time
client.js:12458 loaded.....
client.html:1 Access to XMLHttpRequest at 'http://localhost:9080/time' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
And... that is as far as I was able to comprehend, other than the hint to add a header ?
client.js:12458 button clicked
client.js:12458 URL :http://localhost:9080/time
client.js:12458 loaded.....
client.js:12331 GET http://localhost:9080/time net::ERR_CONNECTION_REFUSED
button clicked
client.js:12458 URL :http://localhost:9080/time
client.js:12458 loaded.....
client.html:1 Access to XMLHttpRequest at 'http://localhost:9080/time' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
client.js:12331 Cross-Origin Read Blocking (CORB) blocked cross-origin response http://localhost:9080/time with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.
Unfortunately that seems to complicate matters even more for me .... (do note that i'm easily confused :-) )But I am.
[Debugger Exception Notification]I have disabled CORRS on firefox.
Project project1 raised exception class 'EHTTP' with message:
No REQUEST_METHOD passed from server.
At address 100027DC2
[Ignore this exception type]
Thank you PascalDragon.
Unfortunately that seems to complicate matters even more for me .... (do note that i'm easily confused :-) )
I have server and client both located in the same directory so i used:
... TSimpleFileModule.Basedir := ExpandFileName('./client'); // mimetypes ...needed for 3.2 ? MimeTypesFile := ExpandFileName('./mime.types'); // pick some route where you want the server to serve the files from HTTPRouter.RegisterRoute('./*', @TSimpleFileModule.HandleSimpleFileRequest); ...
button clicked
URL :http://localhost:9080/time
loaded.....
DoAfterLoad
..and the console with:button clicked
client.js:12458 URL :http://localhost:9080/time
client.js:12458 loaded.....
client.js:12458 DoAfterLoad
client.js:11797 Uncaught
details:__proto__:
$ancestor: {$ancestor: {…}, $class: {…}, $classname: "EDatabaseError", $parent: {…}, $module: {…}, …}
$class: {$ancestor: {…}, $class: {…}, $classname: "EJSONDataset", $parent: {…}, $module: {…}, …}
$classname: "EJSONDataset"
$fullname: "JSONDataset.EJSONDataset"
$module: {$name: "JSONDataset", $intfuseslist: Array(8), $impluseslist: Array(1), $state: 5, $intfcode: ƒ, …}
$name: "EJSONDataset"
$parent: {$name: "JSONDataset", $intfuseslist: Array(8), $impluseslist: Array(1), $state: 5, $intfcode: ƒ, …}
$rtti: {name: "EJSONDataset", $module: {…}, class: {…}, members: {…}, names: Array(0), …}
__proto__: Object
InternalInitFieldDefs @ client.js:11797
InternalOpen @ client.js:11746
InternalOpen @ client.js:12048
DoInternalOpen @ client.js:6481
OpenCursor @ client.js:6949
SetActive @ client.js:6982
Open @ client.js:7450
HandleRequestresponse @ client.js:6577
cb @ client.js:217
DoAfterRequest @ client.js:7785
onLoad @ client.js:12371
cb @ client.js:217
load (async)
DoGetData @ client.js:12315
DoLoad @ client.js:6601
Load @ client.js:7371
btnTimeClick @ client.js:12526
cb @ client.js:217
Unfortunately i couldn't get it to work as seem intended. So, i ended up manipulating the response header manually.
res.SetFieldByName('Access-Control-Allow-Origin', '*');
You should really try to find out why it's necessary for you, cause setting a general CORS header (one with an asterisk instead of specific domains) is a bad idea (TM) - at least if one intends to publish the server on the web.Sorry, I keep forgetting we're on a public forum.... :-[
But in my example to asking time there's no metadata. It just calls a procedure to create an json response sent sent it back to client.Yes, but as far as i am able to tell that is exactly what is the issue.
Why to I get data if I put 'http://localhost:9080/time' in my browser? Is it sending hidden data to call the restserver?For the dataset to work you need to follow a certain pattern, just as you would do for a normal dataset. A normal dataset (let's call it table) has filednames definitions and then rows of data that fill that database.
button clicked
URL :http://localhost:9080/time
loaded.....
DoAfterLoad
Dataset opened
1 -13:21:57
URL :http://localhost:9080/time
Which seems to be what you are attempting to accomplish ?I did this in my other topic. But I got stuck with no response.Sorry, I have no idea you already started a topic about this... topic :)
My actual project calls a complete list by pressing the search button. Build the testserver with the required (header) fields.I have no idea why (yet) but this is what my chromium browser returns in the console:
I see then coming as a log in my restserver, but when the response must sent back a streamwrite error occurs.
And I can't figure it out why.
Uncaught
fMessage: "Field definition 9 in has no or invalid name property"
Also, not sure if it should happen before or after that exception but the search field wasn't mentioned by server, and i seems also to be missing the content of my search query.I have no idea why (yet) but this is what my chromium browser returns in the console:Got it, I think :)Code: [Select]Uncaught
Perhaps you have an idea about the fieldname ?. I will look through the code and see if I am able to track that down but I do not have many time left for today.
fMessage: "Field definition 9 in has no or invalid name property"
An unhandled exception occurred at $000D7558:
EJSON: TJSONObject must be constructed with name,value pairs
$000D7558 TJSONDATA__DOERROR, line 1382 of ./fcl-json/src/fpjson.pp
$000DBF28 TJSONOBJECT__CREATE, line 3200 of ./fcl-json/src/fpjson.pp
$0007C0C4 LOADRESTDATA, line 57 of restdata.pp
$0007D0DC RESTDATA_$$_init$, line 239 of restdata.pp
$00032E70 fpc_initializeunits, line 969 of /home/Pierre/pas/release-build/release_3_2_0/fpcsrc/rtl/inc/system.in
which makes sense as fielddefs come in pairs, and those do not look like field-definitions to me. Unless I'm missing something that I am not aware off with regards to TRestDataSet, otherwise this seems to be your (current) issue.myclient1.js:12607 Uncaught TypeError: Cannot read property 'append' of null
at Object.DSOpen (myclient1.js:12607)
at Object.cb [as FAfterOpen] (myclient1.js:217)
at Object.DoAfterOpen (myclient1.js:6823)
at Object.OpenCursorcomplete (myclient1.js:6946)
at Object.SetActive (myclient1.js:6973)
at Object.Open (myclient1.js:7439)
at Object.HandleRequestresponse (myclient1.js:6571)
at Object.cb [as FAfterRequest] (myclient1.js:217)
at Object.DoAfterRequest (myclient1.js:7774)
at Object.onLoad (myclient1.js:12353)
That's enough for me today :D
in the restserver example, it seems that the original (stored on disk) data is extended (before sending to the client) with an extra field with the name "id" of type "int". That is why the restserver example seems to be 'fixing' all the data by adding an id field using the following loop.....
Thank you very very very much, TRon.You are more than welcome mangakissa.
I have finally results on screen.Cool. Congratulations ... and I have so many questions :)
The problem is documentation. Offcourse you can learn a lot of examples, but comments are very usefull why this is happening.Yes, I agree.
Hopefully there's a 'clean' way to do it otherwise.Yeah, I tried to delve into that subject today but so far and unfortunately turned up empty :-(
Cool. Congratulations ... and I have so many questions :)It's a list with how many packages and which packages a supplier need to fill flowerbulbs in. The real data is a spreadsheet. But spreadsheets are nog multiple users. the second user is read only. If the 'main' colleague want to change it hwen another colleague has opened it, changes can not be made.
For example do you filter the data on the server or on the client ? From your code that I've seen so far it was not clear to me what you exactly intended to do there.
Will you be doing an article on this subject as well ? afaik there is not an example that uses search queries on a json rest dataset, therefore I would be interested. Some of this stuff is still going a bit over my head I'm afraid.i always do that with these projects
Filtering must be done by server. The client must be a stupid client. Only show data when it is requested. I want the client run on a smartphone.Ok, I suspected as such (and it made the most logical sense).
Client runs on a smartphone ? Does that mean you are able to use the pas2js generated code in (what I assume) Android directly ?No. Just using the browser calling a webadress
@mangakissa:
uhm, of course :-[ That's a facepalm for me