Read the statement by Michael Teeuw here.
Help needed simple API based module
-
okay, next thing is your updateISS function. I modified it for you to get you started:
updateISS: function() { var self = this; var url = self.config.apiBase; var opennotifyRequest = new XMLHttpRequest(); opennotifyRequest.open("GET", url, true); opennotifyRequest.onreadystatechange = function() { if (this.readyState === 4) { if (this.status === 200) { var resp = JSON.parse(this.response); this.latitude = resp.iss_position.latitude; this.longitude = resp.iss_position.longitude; this.timestamp = resp.timestamp; this.message = resp.message; } } self.updateDom(); }; opennotifyRequest.send(); }
-
@yawns thank you!
the module shows now this.message and refreshes it with the schedule.
however I am still doing something wrong in my request:updateISS: function() { var url = this.config.apiBase; var self = this; var opennotifyRequest = new XMLHttpRequest(); opennotifyRequest.open("GET", url, true); this.message = "in updateISS"; opennotifyRequest.onreadystatechange = function() { self.message = "request status: "+ to.String(this.status); // not displayed if (this.readyState === 4) { if (this.status === 200) { var resp = JSON.parse(this.response); self.latitude = resp.iss_position.latitude; self.longitude = resp.iss_position.longitude; self.timestamp = resp.timestamp; self.message = resp.message; self.message = "dit gebeurt niet"; } } }; opennotifyRequest.send(); self.updateDom(); }
I can’t set message in that function, for example line 86. I use self/this wrong, or the function isn’t executing. but the code continous because when I set the message before or after that function it gets displayed.
-
@washichi
hm. Did you try to output latitude and longitude as well ingetDom
to see if this is working? -
@yawns No I didn’t, but that should be exactly the same thing.
If I hardcode the (any) variable in “issRequest.onreadystatechange = function() {”
then it just doesn’t display, so it looks like it isn’t going in that function.
but if I hardcode the (any) variable after that function It displays.So I can display the variable (message), but the variable doesn’t get filled with the request.
-
Simple way to test if it entering the function:
Log.error("function entered");
Press F12 in browser, check for console output and refresh the website. If the function is entered you will see “function entered” in the console.
-
thank you! It’s now working :)
I thought that my scheduleupdate was working but it didn’t (only 2 times )
with the Log function I could find the problem easy . -
great. Now tidy up your code ;) and present your module in modules showcase
-
-
@ooom416354 Yes, but other modules are also that.
I used the default module “weatherforecast” it is an simple api based module that gets the data and displays it in a table.I’m now trying to add a map, and then display the ISS current position on that, but implementing this in a module is a lot harder then normal javascript :p.
-
@ooom416354
Yes, kind of. At least with JSON calls without additional headers. The you need to use request and a node_helper