Trying to retrieve yahoo weather using jquery / php / xml

谁说胖子不能爱 提交于 2019-12-24 09:24:54

问题


Whats wrong with this function?

function yahooWeather(){
    var loadPage = 'yahooweather.php?p='+ $("#myCity").val();
    $("#yahoo").html('<img src="loading.gif" align="absmiddle">');
    $("#yahoo").load(loadPage);
}

Is there another way to write this function. Im unsure if its able to read the .val required, tho i know it is set as i used it in a previous function to test that it was being set, so im thinking its maybe my load call.

http://www.wetterkanal.tv/

This is the page. This function once called by clicking the button, should get the value set by the "select city" option then load the weather in a div below. I have set the css to this div as green so i know it loads. I also know that my php script works as if i test it by going to the following:

http://wetterkanal.tv/yahooweather.php?p=ASXX0001

it pulls the weather in correctly. Please help!


回答1:


Your problem is that the button element will reload the page when the button is clicked.

You need to change your onclick attribute to onclick="yahooWeather(); return false;".



来源:https://stackoverflow.com/questions/2172836/trying-to-retrieve-yahoo-weather-using-jquery-php-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!