0

I have an AJAX call made with jQuery to a 500px API:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"/>
<script type="text/javascript">
$(document).ready(function(){
    $('#myButton').click(function() {

        $.ajax({
            url: "https://api.500px.com/v1/photos?feature=editors&page=2&consumer_key=<your-consumer-key>",
            dataType: 'jsonp',
            type: 'GET',
            success: function(result){
                alert("success");
                for(x in result.data){
                    $('#myHtmlList').append('<li><img src="'+result.data[x].image_url+'"></li>');  
                }
            },
            error: function(result){
                alert("Error: "+result);
                console.log(result);
            }
        });

    });
});
</script>

The result of this code is the "Error" alert. If I copy and paste the same url in browser it works and returns the json with the images. I don't understand why the javascript call doesn't work.

I also don't understand why if I make the same code call to an Instagram API, for example:

url: 'https://api.instagram.com/v1/users/' + userId + '/media/recent'
dataType: 'jsonp',
type: 'GET',
data: {access_token: <your-access-token>},

it works.

Luke
  • 1,633
  • 3
  • 23
  • 37
  • it might be because of domain/server is down. you can manually try to reach out to https://api.500px.com. when i tried to open https://api.500px.com, it is showing network error. – TechnoCrat Aug 03 '17 at 12:55
  • No, it works. I get the welcome message from https://api.500px.com . Also if I copy paste url in browser I correctly get the json. – Luke Aug 03 '17 at 13:00
  • ok then it might be not be accessible outside your network. I am still getting same error. have you checked in console for detail error? – TechnoCrat Aug 03 '17 at 13:10
  • Refused to execute script from 'https://api.500px.com/v1/photos?feature=editors&page=2&consumer_key=&callback=jQuery321030225114945226284_1501763816159&_=1501763816160' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled. – Luke Aug 03 '17 at 13:20
  • This should be useful https://stackoverflow.com/questions/24528211/chrome-refuses-to-execute-an-ajax-script-due-to-wrong-mime-type – TechnoCrat Aug 03 '17 at 13:47
  • Problem solved by changing 'jsonp' to 'json' (also need to scan for result.photos instead of result.data). – Luke Aug 03 '17 at 14:00
  • Good. I think link might be helpful for resolving issue. – TechnoCrat Aug 03 '17 at 14:02

0 Answers0