J. Doe J. Doe - 2 years ago 82
Javascript Question

Getting Json with javascript

Json hosted online and should be accessed by a link:

response: "yes"

Getting Json on a device:

<script> $(document).ready(function () {
var url = 'link is here';
$.getJSON(url, function (data) {


Shows nothing. Please advice.

Answer Source

It has to do with the fact that the php needs to grant access. For testing purposes you can add this line on top of your php code:

header('Access-Control-Allow-Origin: *'); 

However this is not safe at all. Therefore you need to write it somehow like this:

header('Access-Control-Allow-Origin: http://mysite1.com');
header('Access-Control-Allow-Origin: http://example.com');
header('Access-Control-Allow-Origin: https://www.mysite2.com')  

This is all mentioned and explained in here: how to bypass Access-Control-Allow-Origin?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download