Update <div> with JSONP value jQuery

I'm getting the temperature from a service called World Weather Online

I'm trying to update the weather into my <span> content like this: (I have all the values correct, it just doesn't change the value when I open my page)

<div class="temperature">
    <span>Washington, USA</span>
    <span id=temp>Temperature</span>
</div>
<script type="text/javascript">
    var uri = "http://api.worldweatheronline.com/free/v1/weather.ashx?q=washington&format=json&num_of_days=1&date=today&key=dfghjkiuytdfghjkj";
    var temp = 0
    $.get(uri, function(r,status) {
        current_temp_C = r.data.current_condition[0].temp_C;
        temp = r.data.current_condition[0].temp_C;
    }, "jsonp")
    $('#temp').text("hola " + temp)
</script>

I know this is probably not the best way I could do it, but any ideas?

Answers


$('#temp').text("hola " + temp) should be inside the get callback

var uri = "http://api.worldweatheronline.com/free/v1/weather.ashx?q=washington&format=json&num_of_days=1&date=today&key=dfghjkiuytdfghjkj"     
var temp = 0    ;                                                                                                                                                                                                                                                        
$.get(uri, function(r,status) {                                                                                                                                                 
    current_temp_C = r.data.current_condition[0].temp_C;                                                                                              
    temp = r.data.current_condition[0].temp_C;                                                                                                        
    $('#temp').text("hola " + temp)       
}, "jsonp")                                                                                                                                       

Need Your Help

Is it possible to reuse an NSKeyedUnarchiver?

cocoa-touch nskeyedarchiver nscoding

I'm working on an iOS game and I'm using the NSCoding protocol to save my levels in my editor and to load them in game. I was wondering if it was possible to somehow reuse an NSKeyedUnarchiver afte...

Jquery dialog href variable not updating in buttons

jquery jquery-dialog

I have a jquery dialog box with three buttons. When a user clicks on a link, I want to grab the href into a variable, prevent the link from executing, and show my dialog box with the options to Sa...