javascript - Update <div> with JSONP value jQuery -


i'm getting temperature service called world weather online

i'm trying update weather <span> content this: (i have values correct, doesn't change value when open 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 not best way it, ideas?

$('#temp').text("hola " + temp) should inside 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")                                                                                                                                        

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -