sails.js+waterline,test question


Yang Ghua

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

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:

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


decsoft

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.



Yang Ghua

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

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


decsoft

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:

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



Yang Ghua

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

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:

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


decsoft

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".



Yang Ghua

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

this is the code:

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


decsoft

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.



Yang Ghua

:) Work! Thanks again


decsoft

You're welcome Joshua!


Everybody can read the DecSoft support forum for learning purposes, however only DecSoft customers can post new threads. Purchase one or more licenses of some DecSoft products in order to give this and other benefits.

This website uses some useful cookies to store your preferences.

I agree. Hide this note. Give me more information.