jquery - Javascript can't communicate with API -


i attempting write webform take city , state user, pass them url api, , put high , low out form.

currently if debug in ie hit error in ajax , shows alert says failure 404, if debug in firefox see 304 response if @ firebug.

i have run ajax call through jsfiddle , gives in alerts correct data. dont think problem ajax itself. have added rest of javascript , html jsfiddle , run , when hit submit button flash of failure alert , jsfiddle says "error: please use post request.". if still same thing lost.

any in getting run great. here code of now.

html:

<body>     <form id="weatherform">         city:<input type="text" id="city" /><br />         state:<input type="text" id="state" /><br />         high:<p id="high"></p><br />         low:<p id="low"></p><br />         <button id="btnsubmit">submit</button>     </form>  </body> 

javascript:

$(document).ready(function () {      $('#btnsubmit').on('click', findtemps) });  function findtemps() {     var city = $('#city').val();     var state = $('#state').val();     var fullurl = 'http://api.wunderground.com/api/(key here)/history_20140303/q/' + state + '/' + city + '.json';      $.ajax({         url: fullurl,         datatype: 'jsonp',         type: 'post',         success: function (parsed_json) {             var high = parsed_json.history.dailysummary[0].maxtempi;             $('#high').val() = high;             var low = parsed_json.history.dailysummary[0].mintempi;             $('#low').val() = low;             alert("high in " + city + ", " + state + " " + high);             alert("low in " + city + ", " + state + " " + low);         },         error: function (e) {             alert('failure ' + e.status);         },         done: function () {             alert('done');         }      }); } 

because cross domain request. browser prevent due same origin policy.

if want use cross domain ajax, there should enable cors in ajax. server should enable it.

also url doesnt supporting jsonp.

there method doing cross domain ajax. make server proxy. ie, there method in server fetches data other domain using http post.. create calls server method only. make call cross domain , return data..


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -