GetJSON in Safari on MacBook v. Safari on iPhone with 10.2.1

If I run the simple code pasted below (with my app ID for
openweathermap obscured here) on Safari on my MacBook it works.
However if I deploy to volt and do the
same on Safari for iOS (10.2.1) it doesn’t. I have spent quite a bit of
time looking at jQuery / ajax conversations on your web board as well as
your documents, but it’s not clear why this wouldn’t work yet.

Thank you in advance for your ideas.

Steve

Function Button1_onclick()
  Dim city, url
  city = ""
  url = "http://api.openweathermap.org/data/2.5/weather?
id=5037649&units=imperial&appid=XXXXXXc6cf60b36959641bb23fXXXXXX"
  GetJSON(url, city, weatherData)
End Function

Sub weatherData(data)
  MsgBox "Temperature is " & (data.main.temp )
End Sub

First, a tip. If you surround your code with triple ticks (```), it will format nicely. I’ve modified your message so you can see this.

What happens if you run it on your MacBoox from the Volt URL?

First, thank you for the tip on formatting code here on the discussion board.

Second, good idea. It does not work on Volt from the mac book Safari browser. Good information. Still a bit of a mystery to me.

Now have a look at the Debugger screen… (You can probably use Chrome for this as well).

Any error messages?

Yeah - you’re onto it here I think.

Error message is

XMLHttpRequest cannot load http://api.openweathermap.org/data/2.5/weather?id=5037649&units=imperial&appid=XXXXXXc6cf60b32959641bXXXXXXXXXX due to access control checks.

It doesn’t look like the GetJSON string query is passing the city. It’s been left empty. The format may require it. See Current weather data - OpenWeatherMap

The city is passed via the ID field (5037649)
http://openweathermap.org/help/city_list.txt

Good point did not notice that.

The message means openweathermap is refusing to do what you’re asking. You’ll need to figure out what the site is looking for. You might check with them for help.

So, I used the same app, essentially, except I set up a simple JSON server on my network; which assumably would NOT have access control issues.

I can get the JSON string when running on a web page from “play” within Appstudio, but after deploying to volt and then running on my computer which is on the same network, it still get access control issues as shown above.

So this is still a mystery…

Are you showing us the full error message?

Entire error message:

[Error] XMLHttpRequest cannot load http://192.168.1.112:3000/employees?first_name=Sebastian due to access control checks.
send (jquery.js:4:15739)
ajax (jquery.js:4:11289)
(anonymous function) (jquery.js:4:12286)
getJSON (jquery.js:4:12098)
onclick (code.js:6)

You’re running into CORS issues, not anything to do with AppStudio itself.

OK. Thank you for your help. I am wondering, then, that a project like LabWeatherSolution.nsx then would not be able to run from Volt because of CORS issues, correct?

A bit more here:

I can disable or enable Cross-Origin Resource Sharing on the simple JSON server I’m running on my network. Using the nsbasic option “Start in Desktop Browser” I can see the error with CORS enabled and see the application work (shown above) with CORS disabled. Basically, I can turn the error on and off.

However by simply deploying to VOLT it doesn’t work in either case, instead showing the access control error:

[Warning] [blocked] The page at https://meister-waits-sternly.volt.live/ was not allowed to display insecure content from http://192.168.1.112:3000/employees?first_name=Sebastian. (jquery.js, line 4)

To clarify:

  1. You want to access your 192.168.1.112 based ip from the volt.live site?
  2. The 192.168.1.112 server operating on port 3000 is your local computer address?

Is this correct?

Yes. That is correct. I am simply pinging that server on the address you mentioned, on an internal network, with a GetJSON request. If I type that address into any web browser it returns the JSON (on the internal network).

However using a GetJSON request in NSB (because it is based on XMLHttpRequest) is blocked because of the browser’s same origin policy.

I’m not sure how to get around it. I’d rather not write server side PHP - I have a pretty robust server that I can access written in node.js. But I’m stuck on how to make that work within Appstudio/NSB.

Thank you for your help.

Can anyone outside of your 192.168.1.112 access your network? For example, load in a simple index.html page?

I think, If I understand your question, the answer is no. You’d have to be on my internal network to access that. And I don’t open up that internal port or forward it.

My use case is to have an iOS device pinging that server that is also sitting on the internal network however, so maybe I don’t understand Volt well enough yet to get my system architecture nailed down.

Thanks again.

If no one can access your network, then you will always get that error. It is impossible unless you securely open up your network.

There are some workarounds but they are not very elegant but it would work.