Recent

Author Topic: Request is not working on demodb  (Read 2033 times)

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Request is not working on demodb
« on: June 17, 2020, 11:29:50 am »
On $pas2js/demo/fcldb the're several examples to load data from a restserver.
I compiled restserver and run it. It opens a console and start the server on port 3000.
Then I load demodb in Lazarus and compile it with pas2js. After compiling I start demodb.html in my browser (firefox). It shows a button wit text 'fetch countries'. But the button doesn't work. I see nothing in the console of the restserver.

If I do a request in my browser with url http://localhost:3000/countries the json file is loaded and showed on screen. That means restserver is running.

Demorest is doing nothing. It doesn't show anything on screen.

'Data Abstract for Pas2JS' works.

How do I get feetback from the restserver?

Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Request is not working on demodb
« Reply #1 on: June 17, 2020, 11:47:27 am »
This is what webconsole shows when clicking on the button:
Quote
Cross-Origin-aanvraag geblokkeerd: de Same Origin Policy staat het lezen van de externe bron op file:///C:/Users/john/Documents/Lazarus/projects/pasjs/demo/fcldb/countries.json niet toe. (Reden: CORS-aanvraag is geen http).

Cross-Origin-request blokked: the Same Origin Policy is not allowed to load external source on file file:///C:/Users/john/Documents/Lazarus/projects/pasjs/demo/fcldb/countries.json
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Request is not working on demodb
« Reply #2 on: June 17, 2020, 12:22:30 pm »
changed
Code: Pascal  [Select][+][-]
  1. xhr.open('GET', 'countries.json', true);
to
Code: Pascal  [Select][+][-]
  1. xhr.open('GET', 'http://localhost:3000/countries/', true);
sends a request to the restserver. But this comes with an errormessage
« Last Edit: June 17, 2020, 12:33:02 pm by mangakissa »
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: Request is not working on demodb
« Reply #3 on: June 17, 2020, 01:23:25 pm »
This is what webconsole shows when clicking on the button:
Quote
Cross-Origin-aanvraag geblokkeerd: de Same Origin Policy staat het lezen van de externe bron op file:///C:/Users/john/Documents/Lazarus/projects/pasjs/demo/fcldb/countries.json niet toe. (Reden: CORS-aanvraag is geen http).

Cross-Origin-request blokked: the Same Origin Policy is not allowed to load external source on file file:///C:/Users/john/Documents/Lazarus/projects/pasjs/demo/fcldb/countries.json

Ah, right, I have installed myself an addon for my browser to temporary disable CORS for selected sites (in my case localhost), to avoid this problem.

changed
Code: Pascal  [Select][+][-]
  1. xhr.open('GET', 'countries.json', true);
to
Code: Pascal  [Select][+][-]
  1. xhr.open('GET', 'http://localhost:3000/countries/', true);
sends a request to the restserver. But this comes with an errormessage


Ugh... what could that problem be again? %)

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Request is not working on demodb
« Reply #4 on: June 17, 2020, 01:38:42 pm »
There's an atachment with the message.
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: Request is not working on demodb
« Reply #5 on: June 17, 2020, 03:52:11 pm »
There's an atachment with the message.

Yes, I've seen that. Doesn't change my reply though, cause that was to that message...

 

TinyPortal © 2005-2018