1

I am trying to get the json data from a web API

http://www.streetdirectory.com/api/?mode=search&act=all&profile=sd_default&q=640724&limit=1&show_additional=0&output=json

Using ajax, I am encountering the issue whereby I am getting this error.

var addresses = new Array();
getAddress();
var myURL = "http://www.streetdirectory.com/api/?mode=search&act=all&profile=sd_default&q=640724&limit=1&show_additional=0&output=json";
function getAddress() { //get addresses from streetdirectory web API
        $.ajax({
            type: "GET",
            url: myURL,
            dataType: "json",
            success: function(response){
                addresses = response;
                alert(response);
            },
            error: function(e) {
                alert('Error: '+e);
                console.log('Error: ' +e);
            }  
        });
}

Updated with error on console. enter image description here

It seems like it's because I am directly accessing the html. I have since moved it to host on my localhost. But it's still having the error, without any description now...

enter image description here

enter image description here

After shifting my function call to after my function definition, I am now getting this error.

Community
  • 1
  • 1
Gavin
  • 2,784
  • 6
  • 41
  • 78

3 Answers3

2

You should use console.log instead of alert. Logging to the console will allow you to investigate the objects being returned.

Since this is an ajax call and the error handler is being called, it's likely that the status of the response is NOT 200.

Aaron Cicali
  • 1,496
  • 13
  • 24
1

"If you are working on web project and want to get data from different site, Sometime you get such type of error: Cross-Origin Request Blocked"*

I think you could find some additional information reading this post cross-origin-request-blocked

Community
  • 1
  • 1
EspA
  • 51
  • 4
0

I resorted to using an extension to remove the blocking on google chrome.

https://stackoverflow.com/a/28848096/771355

Update:This might be a better fix. By using a proxy

https://crossorigin.me/

Community
  • 1
  • 1
Gavin
  • 2,784
  • 6
  • 41
  • 78