Normally when we call a JSON file while doing web development, it exist in the same folder and we use get method to access it. So, when i want to call it via node red html, how can i call it?
Also when I am trying to access via localhost server i am getting "CORS header ‘Access-Control-Allow-Origin’ missing" error.
Please suggest a way to access JSON using ajax.
Thank for your suggestion. I actually want to populate a drop down list using this JSON file. Which will allow me to dynamically update the drop down list in the node with the use of oneditprepare.
Thanks a lot Steve, its working when i store the json file in resources folder.
I believe its also possible to get the data from another localhost port but when i am trying, it i am getting "CORS header ‘Access-Control-Allow-Origin’ missing" error.
When i send the get request for the same port from http request node i am getting a JSON output in the debug window.
How can i get access to this port from the node html file?
The server serving that JSON will need to set correct headers e.g.
Access-Control-Allow-Origin : "*"
You could try adding
dataType: "jsonp",
to the ajax request.
If you have access to the s/w serving and can modifiy it, you need to enable cors.
Failing that, you could create a proxy to the other source.
In summary:
This is not something node-red can solve for you as it is external to node-red completely (browser --> other web server). You can not enable crossDomain calls yourself, the source must have CORS enabled for this to work.
Since I am using oneditprepare and ajax, the list is loading every time when I open the edit property window. The selected option is not being saved once i reopen the edit properties window.
I tried to give an Ajax call only when the search button is clicked, but still the item is not saving and otherwise empty.
What can i do to save the data? The serial node works on the same functionality and i tried to follow it but was unsuccessful.
Thank a lot for the information and helping me out.