Tuesday, 10 September 2013

ajax get works on localhost, not on live https site

ajax get works on localhost, not on live https site

I am calling an internal route of my app through an ajax get (no
cross-site scripting)
Archive/WeatherForecast?lat=63.8299&lng=20.25484
It works great on my localhost, but on the live environment, where I have
https, it throws me a "http 403, forbidden" error.
If it could have anything to do with the problem, that route makes a php
request to
$api_url = "http://api.met.no/weatherapi/locationforecastlts/1.1/";
which is obviously not https, but the client shouldn't be concerned about
that, because what is then served to the client is data from a file saved
to disk (based on info from that http route above). I have checked the
files produced and they are actual xml files with accurate content.
This is how the get request is done:
var url = '{{ path('WeatherForecast') }}';
var lat = $('#data_21').val();
var lng = $('#data_22').val();
var full_uri = url + '?lat=' + lat + '&lng=' + lng;
console.log('calling:' + full_uri);
jQuery.ajax({
url: full_uri,
success: function(result) {
$('#weatherdata').html(result);
},
error: function(result) {
$('#weatherdata').html('kunde inte hämta väderdata');
},
asynch: false,
});
Moreover, if I go into the chrome console to review the error, it shows me
what route I tried to ajaxGet, and if I click on that route to open it in
a new tab, it suddenly works and presents me with the data that the jQuery
AjaxGet threw "403 forbidden" on...
It probably doesn't matter but it is a symfony2 app.

No comments:

Post a Comment