0

May I ask for help with the jquery ajax syntax needed to consume the NWS forecast data at the following url?:

http://forecast.weather.gov/MapClick.php?lat=38.14000&lon=-78.45000&FcstType=digitalDWML

I've tried several possibilities and suspect an issue with my dataType spec. Specifying xml and json results in an "Access-Control-Allow-Origin" error. Specifying jsonp results in 'Unexpected token <' error that I haven't been able to track down. My jsonp attempt is given in the jsfiddle linked below. Any help will be appreciated.

http://jsfiddle.net/gbkester/hgt8bvb8/

$(document).ready(function() {
$.ajax({
    type: "GET",
    url: "http://forecast.weather.gov/MapClick.php?lat=38.14000&lon=-78.45000&FcstType=digitalDWML",
    dataType: 'jsonp',
    success: function (json) {
        console.log(json)
    }
})

})

Brian
  • 15
  • 3
  • The problem is that you're making a cross domain content call (your site the browser sits on but is also calling nws). Try enabling CORS headers in your server. Setting the datatype is useful only if the server will respond accordingly. See here:http://stackoverflow.com/questions/15412226/access-control-allow-origin-error – Jason Aug 26 '14 at 19:51
  • Thanks for the response Jason. I'm hoping to find a way to make it work with jsonp. On a whim, I tried changing the FcstType variable from 'digitalDWML' to 'digitalJSON.' This does seem to give a JSON structured return, but both Chrome and Firefox throw an odd syntax error pointing to the colon in the first key:value pair. Any idea why? I've updated the Fiddle. – Brian Aug 26 '14 at 21:45

1 Answers1

0

I worked around the problem by setting up a server-side proxy. Now browsers don't face the cross-origin blocking. Thanks for your help

Brian
  • 15
  • 3