我试过用这样的jquery进行ajax调用:(文件名是BR_states.txt并且匹配正确)
<script>
function changeSelectedShippingCountry(select){
var countryCode = select.options[select.selectedIndex].value;
if (countryCode === 'AR' || countryCode === 'BR' ||
countryCode === 'CA' || countryCode === 'IN' ||
countryCode === 'IT' || countryCode === 'JP' ||
countryCode === 'MX' || countryCode === 'NL' ||
countryCode === 'TH' || countryCode === 'US') {
var urlToFile = countryCode + "_states.txt";
$.ajax({
url: urlToFile,
error: function() {
alert('error ajax');
},
dataType: 'text',
success: function(data){
alert(data);
var stateCells = document.getElementsByClassName('stateCells');
stateCells[0].style.display = "table-cell";
stateCells[1].style.display = "table-cell";
var options = data.split(/\n/);
$('select[name="state"]').html('');
for (i=0; i<options.length; i++) {
var optionKeyVal = options[i].split('=');
$('select[name="state"]').html('<option value="'+ optionkeyVal[0] +'">'+ optionKeyVal[1] +'</option>');
}
}
});
} else {
var stateCells = document.getElementsByClassName('stateCells');
stateCells[0].style.display = "hidden";
stateCells[1].style.display = "hidden";
}
}
</script>
但我总是将当前的html页面作为回复。我试图将文本文件直接放在Webcontent文件夹下,也放在Java Resources文件夹的src文件夹下。哪里可以访问?
我在将javascript文件加载到标签时也遇到了问题。
我使用Apache tile。这可能是个问题吗?
结构:
的WebContent -tiles -META-INF -WEB-INF -layouts BR_states.txt
答案 0 :(得分:0)