我使用此脚本根据带有 json 响应的 ajax 请求更新表格单元格。它不会更新指定的表格单元格。我的 json 字符串格式不正确吗?
$(document).ready(function() {
$('select.swcomp').change(function () {
var res_id = $(this).val();
var index = $(this).data('index');
$.ajax({
type: 'POST',
url:'http://skiweather.eu/v3/ajax/compare_snow.php',
data: '{ "res_id":"' + res_id + '", "index":"' + index + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (response) {
$('#destin_' + index).html(response.resort);
$('#snowval_' + index).html(response.snow_valley);
$('#snowmnt_' + index).html(response.snow_mountain);
}
});
return false;
});
});
html
<select name="resort_1" class="swcomp" data-index="1">
<option value="NoResort">resorts</option>
<option value="6">Adelboden</option>
<option value="237">Davos</option>
</select>
<table>
<tr><td id="destin_1">res</td></tr>
<tr><td id="snowval_1">val</td></tr>
<tr><td id="snowmnt_1">mnt</td></tr>
</table>
json
var response =[{"snow_valley":"40","snow_mountain":"40","resort":"Adelboden"}]