AJAX 是与服务器交换数据并更新部分网页的技术,在不重新加载整个页面的情况下。
function fnLoadData(cityId, fnHandlerData) {
// ajax
$.ajax({
//请求的服务器url
url: "http://t.weather.sojson.com/api/weather/city/" + cityId,
//请求方式
type: 'get',
//请求返回的数据格式
dataType: 'json'
})
// 成功获得数据
.done(function (response) {
//回调函数 用于处理数据
fnHandlerData(response);
})
// 失败
.fail(function () {
alert("网络异常,请重试!")
});
}