Access-Control-Allow-Origin in Phone Gap

I decided to develop an application that uses an open API that provides timetables for buses and subways in the city.

I decided to develop this application using HTML5 so that with the help of something like a telephone connection I could deploy several platforms.

During development, I found that I could not access the JSON response from the API due to the presence of the xmlhttprequest-can not-load No 'Access-Control-Allow-Origin' header on the requested resource

So, I decided to use the usual provider web space as a bridge with the php function to which I am sending a request, and which can receive a response from this API service and send the JSON result back to my HTML page.

I have two questions for which the start page or key will also be evaluated: 1) This problem in Access-Control-Allow-Origin is what will appear if I developed the application in my own code (java and ObjC)?

2) If HTML5 and javascript are compiled on a calling card, I still won’t be able to access this API service and will I still have the same problem and still have to use the php bridge?

+4
source share
3 answers

1) This Access-Control-Allow-Origin problem is what will also appear if I developed the application in my own code (java and ObjC)?

No, this is a security feature that only browsers implement.

2) HTML5 javascript , - API, , php-?

PhoneGap , . , -. API DO , , API, .

+3

I had a similar problem when trying to use an external API (supermarket api) and found that when I actually downloaded my code to the phonegap assembly and then downloaded it to the device, the http request was resolved.

0
source

Source: https://habr.com/ru/post/1541150/


All Articles