We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm not sure why nothing is appearing here.
I'm attempting this tutorial, using Brackets:
This is my code:
function setup() {
loadJSON("http://" + "api.open-notify.org/astros.json", gotData, 'jsonp');
}
function gotData(data) {
console.log(data);
}
I get nothing. Well, some errors:
SLint Problems
×
3 Missing 'use strict' statement. loadJSON("http:/ /api.open-notify.org/astros.json", gotData, 'jsonp');
3 Expected 'loadJSON' at column 5, not column 3. loadJSON("http:/ /api.open-notify.org/astros.json", gotData, 'jsonp');
3 'loadJSON' was used before it was defined. loadJSON("http:// api.open-notify.org/astros.json", gotData, 'jsonp');
3 'gotData' was used before it was defined. loadJSON("http:// api.open-notify.org/astros.json", gotData, 'jsonp');
7 Missing 'use strict' statement. console.log(data);
7 Expected 'console' at column 5, not column 3. console.log(data);
7 'console' was used before it was defined. console.log(data);
Answers
Try using function preload.
Kf
This forum mangles code URLs. To work around this in both examples above, separate the protocol and argument strings in your code examples into two strings combined with '+'. This works in both code and forum formatting.
}
(done)
Hmm there's still a problem. I've coped your code above, still doesn't work. I'm wondering if I haven't imported the libraries correctly, as I've only just started using Brackets. I've tested that url and it isn't broken, it should work in the code.
http://Bl.ocks.org/GoSubRoutine/7a567f0510b338b6d0fc1ef53f24f10e
"index.html":
"sketch.js":
Alternative version 2.0: :bz
http://Bl.ocks.org/GoSubRoutine/7a567f0510b338b6d0fc1ef53f24f10e
And now version 3.0, using
ol
+li
w/ style(): O:-)http://Bl.ocks.org/GoSubRoutine/7a567f0510b338b6d0fc1ef53f24f10e
This is advanced for me, thank you for these solutions. Can you explain why you broke up the url like this?:
<pre lang=js></pre>
tags. ;;)false
, if I wished so. :)>-P.S.: Looking at your post, seems like just
http://
is already enough to get mangled. 3:-OGuess I'm gonna need to split it as well now in order to avoid mangling:
const HTTP = 'http' + '://'
:-<Here's a similar online example using createP() for displaying weather info: :bz
http://Bl.ocks.org/GoSubRoutine/5fbc03e019c53254a2ba7e7fd3318b45
By Jove it works! I'm unpacking your first version, it works in Brackets. Just an observation, isn't it a little inefficient to have to do this sort of thing with every url in every post in this forum? How often is this forum visited?
Well, I try to post readable code not only for the OP, but for any other probable visitors in the future. $-)
And when feasible, a runnable online version in order to prove my examples indeed work! >-)
I appreciate it.
@GoToLoop
Could you comment on the jsonpOptions in your code please:
jsonObject = loadJSON(PATH, print);
The reference did not provide any details. I am curious about what other options are there and what does you code do: https://p5js.org/reference/#/p5/loadJSON
Kf
At my
loadJSON(PATH, print)
, 1st parameter is a pathstring
; and 2nd is a callbackfunction
. :-B@GoToLoop
I don't see the call back function. You use the json data available directly from the handler you setup in preload. Am I missing something?
Kf
print() is a p5's method: https://p5js.org/reference/#/p5/print
So I can use it as a function callback success argument for loadJSON(). B-)
BtW, here's another example, but w/ loadXML() instead: ;;)
xml = loadXML(REMOTE && URI || FILE, print, console.warn);
https://forum.Processing.org/two/discussion/22668/issue-loading-xml-feed-in-p5js#Item_4
http://p5js.ProcessingTogether.com/sp/pad/export/ro.CJr$SpnCkgIPQC/latest
https://p5js.org/reference/#/p5/loadXML
:-bd Really neat. Thank you for your demos.
Kf