-1

I have a json file mydata.json which is hosted on www.example.com/mydata.json

    [{"id":1,"name":"site1"},
    {"id":2,"name":"site2"},
    {"id":3,"name":"site3"},
    {"id":4,"name":"site4"}]

I am trying to fetch all data using jquery ajax....

     $.ajax({
        url: 'http://www.example.com/mydata.json',
        dataType: 'json',
        complete: function(data){
            console.log(data)
        },
        success: function(data){
            console.log(data)
        }

    });

I get an error "No 'Access-Control-Allow-Origin' header is present on the requested resource." i tried changing dataType: 'jsonp' also tried ?callback=? ,also tried .getJson method nothing worked... do we have to return something from external json file(it is under my control)... is it better to use js instead of json file?

NOte: I can not set header... or change .htaccess

Friend
  • 1,326
  • 11
  • 38
  • 62

1 Answers1

1

Put this: header('Access-Control-Allow-Origin: *'); in PHP or change server configuration.

See that: how to bypass Access-Control-Allow-Origin?

Community
  • 1
  • 1