0

I am pulling json array data from my Instagram api: https://www.instagram.com/finkavenue/media/

There are a pair of parentheses () within the data. Those parentheses are throwing the error in my console upon ajax request:

SyntaxError: missing ; before statement

How can I purge or cleanse my json data of the parentheses and do an ajax request?

My ajax code is:

var url = "https://www.instagram.com/finkavenue/media/";

displayImgs(url);

function displayImgs(url) {
    $.ajax({
            type: "GET",
            dataType: "jsonp",
            cache: false,
            url: url,
            success: function(data) 
            {   
              alert(JSON.stringify(data));             
              console.log(data);

                 for(var i=0;i<data.length; i++)
                 {

                     $("#instagram").append('<img src="'+data.data[i].images.standard_resolution.url+'" height="350" width="350">');
                 }
            }
    });
}
ThomasAFink
  • 1,257
  • 14
  • 25
  • Try changing `dataType` to `json` – guest271314 May 23 '16 at 14:13
  • Already tried json. No error however no data is returned either. I tried jsonp with another api and it worked fine. @guest271314 – ThomasAFink May 23 '16 at 14:16
  • 1
    The problem is because the response is `JSON`, not `JSONP`. However when you set the request to a JSON data type you the standard 'No Access-Control-Allow-Origin' header error as the Instagram URL does not allow cross-domain requests. Check the duplicate question I marked for a full explanation of the issue and several workarounds. In short, you cannot achieve what you are trying to do in JS code alone due to the SOP restriction. – Rory McCrossan May 23 '16 at 14:21
  • https://api.instagram.com/v1/tags/finkavenue/media/recent?access_token=Token works @RoryMcCrossan – ThomasAFink May 23 '16 at 14:40
  • 1
    That does indeed work (access token error aside), but that's also calling the Instagram API, not their main site. – Rory McCrossan May 23 '16 at 14:42
  • Ok that makes sense! Thanks! @RoryMcCrossan – ThomasAFink May 23 '16 at 14:48

0 Answers0