0

我正在尝试在网页的 div 中显示带有 $ & ajax 的 JSONP 数据。我希望定期更新这些数据。但是下面的代码只显示一次数据,然后它就永远不会改变。我可以做些什么来显示数据,然后在提要中的信息更改时实际更改?

<script type = "text/javascript">
   setInterval(function refreshWeather() { 
   $(function() {
   $.ajax({
   url : "http://api.wunderground.com/api/mykey/conditions/forecast/q/autoip.json",
   dataType : "jsonp",
   success : function(parsed_json) { 
   var temp_f = parsed_json['current_observation']['temp_f'];
   var feelslike = parsed_json['current_observation']['feelslike_f'];
   var forecast = parsed_json['forecast']['txt_forecast']['date'];
   $('#content13').replaceWith(temp_f + " feels like " + feelslike);
     }
    });
    });
   }, 90000);

  </script>
4

1 回答 1

1

这似乎有效:

$(function () {
    var refreshWeather = function () {
        $.ajax({
            url: "http://api.wunderground.com/api/mykey/conditions/forecast/q/autoip.json",
            dataType: "jsonp",
            success: function (parsed_json) {
                var temp_f = parsed_json['current_observation']['temp_f'];
                var feelslike = parsed_json['current_observation']['feelslike_f'];
                var forecast = parsed_json['forecast']['txt_forecast']['date'];
                $('#content13').replaceWith(temp_f + " feels like " + feelslike);
            }
        });
    };

    refreshWeather();
    setInterval(refreshWeather, 90000);
});

http://jsfiddle.net/Nsu3h/

于 2013-01-29T18:13:57.900 回答