This is the website link can anyone help me get the JSON data (only names or numbers will be fine) from the above link with a simple JavaScript (or AngularJS) and html codes example.
-
Not a duplicate. This is a question specific to Ionic. – Andrew Mar 14 '16 at 07:46
-
@Andrew If its not a duplicate, fix the question to make that apparent. A claim in comments doesn't set it apart. – Daedalus Mar 14 '16 at 08:37
-
@Daedalus The question has been edited and the comment I am responding to has been deleted, but originally it had to do with making AJAX request to 'any' website within Ionic and it was correctly tagged with [ionic-framework]. CORS was not (directly) a factor (and JSONP?!?). Though the duplicate tag is (now) indeed accurate, I am getting pretty disheartened seeing links to inappropriate answers -- especially in [javascript]. It seems to me that some people are racing to post the first duplicate link they can find, regardless of whether it helps the OP or not. New members deserve better. – Andrew Mar 14 '16 at 09:49
-
yeah those "over expertise" marked duplicate rather than helping me. All I want to know is just how to make a simple call from a given website [link](http://manipurpolice.org/teldir.html) to get JSON. But some websites doesn't have JSON data instead they have saved in HTML, that's the real problem I have now, that's y I can't call externally. I have to work JSON internally inside my project. – Thoudam Albert Mar 15 '16 at 06:09
-
@ThoudamAlbert In this case there was a problem with your question. I don't blame you at all. It is a challenge for new members to ask good, clear questions. And it is very difficult for new coders (and even experienced coders learning a new language) to understand their problem well enough to ask a clear question. I know how frustrating it is. Keep asking though. BTW, be sure to read up on [How to create a Minimal, Complete and Verifiable example](http://stackoverflow.com/help/mcve). BTW, just making a minimal example often helps you figure out your problem, and it is well worth the effort. – Andrew Mar 15 '16 at 08:54
2 Answers
Since you are talking about Ionic (and not generic web development), you should probably read their blog post on the issue of loading Cross-Origin content. The takeaway is simply this:
1) The compiled app you deploy to a device will operate within the standard sandboxed webview security model and (currently) should not fail when making valid requests to external sites. I believe this is the case for any webview in any iOS/Android app (as long as outbound requests have been enabled in your config). This means that you can potentially load remote data from any source, even ones you don't control.
2) The problem you undoubtedly will face is developing the app in your browser, which may not be able to make a cross-origin request. Whether it can or not depends on what the server's CORS headers say.
3) The way to get around the CORS issue during development is to either enable it via HTTP headers on the server (if you control it) or set up a proxy server.
I personally do my development using a local web server to simulate live server responses and then switch the URLs for the staging/production server when it is time to do testing on a device. This way, I can set up the HTTP headers and simulate latency, errors and empty responses. But based on what I've read, Ionic offers a pretty decent solution right out of the box.

- 14,204
- 15
- 60
- 104
If you mean:
"Can I get JSON info from ANY webpage?"
Then, that depends on if they have a text file with no HTML tags, just an object:
{
numKitties: 27,
kittyNames: ["Bob", "Alice", "Norris", "Alinea"]
}
Then you would of course call this text file and use it to your will.
But if you mean:
"Do I have to load any external files (like jQuery) in order to use JSON?"
Then no, you don't have to, because JSON is in the window
Object of your browser, so you can use it anywhere you want, as long as you're connected to the Internet, you'll be fine.
Hope this helps!

- 30
- 1
- 6
-
Thanks for the suggestion. It give me some ideas. can you please explain more on if the website has HTML tags. example: [link] (http://manipurpolice.org/teldir.html) – Thoudam Albert Mar 14 '16 at 07:44
-
Well, first of all, JSON works with just text files as far as I know. Take this one for example: http://www.w3schools.com/json/myTutorials.txt, right click " View Page Source", and you'll see a plain text file. JSON can use these text files for getting data from the Internet for whatever. – Flostin Mar 14 '16 at 16:58