我希望能够有一个包含ajax调用的js函数来返回ajax成功处理程序返回的值。
这是我现在所处位置的问题。我正在使用虚拟json端点进行说明。我希望someFunction返回我当前在控制台中登录的相同内容。
http://jsfiddle.net/ivansifrim/qgfo6zqe/
$(document).ready(function(){
function someFunction(){
$.ajax({
url: 'http://api.openweathermap.org/data/2.5/weather?id=2172797',
type: 'GET',
success: function(result) {
console.log(result.coord);
$("#result").html(result.coord.lat);
},
error: function(result) {
console.log("something went wrong");
}
});
};
$("#click-test").click(function(){
someFunction();
});
});
我真的很感激一些帮助,并且非常乐意在需要时提供更多背景信息。谢谢!