0

I am trying to find the simplest way to interface to a HTTP GET API: http://zipcodedistanceapi.redline13.com/API I want to get able to pass in a zip code and get the results in json/xml/csv.

I have copied this code (https://stackoverflow.com/a/4033310) but I think I'm running into the problem of trying to access an external server. However, this website (http://web-sniffer.net/) is able to successful connect to the API and return the values, so it must be possible!

I have no experience of jQuery/Ajax/other(?) so as much help/code as possible would be greatly appreciated!

Community
  • 1
  • 1
user3320795
  • 523
  • 2
  • 6
  • 17

1 Answers1

0

Short answer: this is impossible with current conditions


Explanation:

About request

You can sent cross-origin requests with JSONP, but server should handle this type. Your server doesn't work with it, because response fails validation (consider sample jsfiddle):

var options = {
    apiKey: 'j6M7YeDBfIo2QC3wBkS9zwJt63Q0DzKWGw3ELHg0pE3gh6MSqE10bKuhOkirU2oB',
    format: 'json',
    zip1: '64052',
    zip2: '52242',
    units: 'km'
};

$.ajax({
    url: 'http://zipcodedistanceapi.redline13.com/rest/'+options.apiKey+'/distance.'+options.format+'/'+options.zip1+'/'+options.zip2+'/'+options.units,
    dataType: 'jsonp',
    success: function(responseData){
         alert(responseData);
     },
});

About web-sniffer.net

It works with server side assistance. For example, request to your server:

Request URL:http://web-sniffer.net/
Request Method:POST
Form Data:
    url:http://zipcodedistanceapi.redline13.com/rest/j6M7YeDBfIo2QC3wBkS9zwJt63Q0DzKWGw3ELHg0pE3gh6MSqE10bKuhOkirU2oB/distance.json/64128/63401/km?jsonp=jQuery111196138642730146370549383006431216814089566_1392673427348&_=1392673427349
    submit:Submit
    http:1.1
    gzip:yes
    type:GET
    uak:0
terales
  • 3,116
  • 23
  • 33