#1 2016-06-29 03:57:20

reg4app
Member
Registered: 2016-05-16
Posts: 147

sails.js+waterline,test question

I have build a backend with sails.js+waterline
get data like :http://127.0.0.1:1337/App_Dist/A1a

[
  {
    "aid": 6,
    "PDname": "something",
    "dist": "otherthing",
    "Bname": "someguy's name"
  }
]

and i change the sample JSON3 to test the data

SimpleGet "App/files/data.json" "[Data]"   --->SimpleGet "127.0.0.1:1337/App_Dist/A1a" "[Data]"

HtmlContent1:

<strong>ID:</strong> [Data.PDname]
<br />
<strong>Name:</strong> [Data.dist]
<br />
<strong>Lastname:</strong> [Data.Bname]

but while i click the button,the data not show up....


Joshua.Y

Offline

#2 2016-06-29 09:21:40

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: sails.js+waterline,test question

Hello Joshua,

Try to change the URL from "127.0.0.1:1337/App_Dist/A1a" to "http://127.0.0.1:1337/App_Dist/A1a". Note the "http://" first. I am not sure if this is the problem, but you can try it. On the other hand, assert the problem is not related with "CORS": remember we must allow "CORS" in our server script in order to accept our app's requests.

Take a look here http://enable-cors.org/ and finally tell me if this can help you in some way!

P.S. Try also to run the application in Firefox with the Developer tools open (press F12 in Firefox)... maybe we can get a little more information about the cause of the problem.

Offline

#3 2016-06-30 03:54:03

reg4app
Member
Registered: 2016-05-16
Posts: 147

Re: sails.js+waterline,test question

change the URL from "127.0.0.1:1337/App_Dist/A1a" to "http://127.0.0.1:1337/App_Dist/A1a"
and set the config in sails ,cors.js

   
   allRoutes: true,
   origin: '*',
   credentials: true,
   exposeHeaders : 'Content-Type',

in firefox F12 still get  error like this:

The token 'cache-control' is invalid, From CORS header 'Access-Control-Allow-Headers' from CORS preflight channel


Joshua.Y

Offline

#4 2016-06-30 08:12:16

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: sails.js+waterline,test question

Hello Joshua,

You must to allow the "cache-control" header for "CORS" requests. Here is how we can enable "CORS" from a particular PHP script, maybe this can help you in some way:

// Enable CORS (http://enable-cors.org/server_php.html)
header('Access-Control-Allow-Origin: *');
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
  if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
    header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
  if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
    header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
  exit;
}

And here is how we enable "CORS" from an "htaccess" file for the Apache server:

Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "POST, GET, PUT, OPTIONS, PATCH, DELETE"
Header always set Access-Control-Allow-Headers "X-Accept-Charset,X-Accept,Content-Type,cache-control,if-modified-since,pragma"

Offline

#5 2016-06-30 10:44:00

reg4app
Member
Registered: 2016-05-16
Posts: 147

Re: sails.js+waterline,test question

after change the config file (cors.js) in sail.js to below:


allRoutes: true,
origin: '*',
headers : 'Content-Type,cache-control,if-modified-since,pragma',
methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD'

FireFox  F12 show no error,but the value still not show up!


I finally found out that :

the data would not show up ,if they are like this:

[
  {
    "aid": 6,
    "PDname": "sss1",
    "dist": "bbbb1",
    "Bname": "12kiokkf"
  }
]

but the data would show up ,if they are like this:

  {
    "aid": 6,
    "PDname": "sss1",
    "dist": "bbbb1",
    "Bname": "12kiokkf"
  }

Joshua.Y

Offline

#6 2016-06-30 21:17:31

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: sails.js+waterline,test question

Hello Joshua,

Sorry for the delay. I expend all the day into the hospital with my mom. About your last post, certainly the first one is an "Array" which contains an "Object". So probably the data is ready, but inside the "Array" and not directly as in the second sample code, because this last yes, is an "Object" alone and not inside any "Array".

Remember App Builder have actions for both "Arrays" and "Objects", then, if you really wanted, you can access to the first "Array" in order to extract the "Object".

Offline

#7 2016-07-01 03:01:50

reg4app
Member
Registered: 2016-05-16
Posts: 147

Re: sails.js+waterline,test question

Thanks for your respond,please give my best wishes to your mom,always family first right!?

this is the code:

SimpleGet "http://127.0.0.1:1337/App_Dist/A1a" "[DataArray]"

ArrayGetItem "DataArray" "0" "[Data]"

and i can get the data show up,but just need to click the Button twice..
please take your time,i can wait


Joshua.Y

Offline

#8 2016-07-01 08:57:23

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: sails.js+waterline,test question

Hello Joshua,

Thanks for your kindly words. The above code is not completely correct, because "SimpleGet" is executed asynchronously, that is, the next action is executed probably without having a response from the server.

The "SimpleGet" action can be good, but not in this context. So what we can do? Use the HttpClient control instead, and extract the "response object" on the HttpClient control's Success event.

Offline

#9 2016-07-03 13:13:05

reg4app
Member
Registered: 2016-05-16
Posts: 147

Re: sails.js+waterline,test question

HttpClearData "HttpClient1"

HttpExecute "HttpClient1"

smile Work! Thanks again


Joshua.Y

Offline

#10 2016-07-03 20:02:42

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: sails.js+waterline,test question

You're welcome Joshua!

Offline

Board footer

Powered by FluxBB


Copyright ©2018 DecSoft. All rights reserved.