对于开始时缺乏知识表示歉意...
我们网站上有一个页面根据用户选择的尺寸宽度和数量显示价格不幸的是动态计算器没有显示价格,即使脚本似乎正在计算价格...
任何人都可以帮助我哪里出错了:-(
当我在控制台中调试时,它可以正确显示信息,但就是不显示!!!
编辑:应该输出价格的 javascript 是
<script>
$(function() {
$('#inputqty').keyup(function() {
var inputqty = $('#inputqty').val();
var sku = $('#selSKU').val();
$.getJSON('pricecheck.cfc?method=getPrice&returntype=JSON&sku='+sku+'&qty='+inputqty, function(data) {
$("#divPrice").html(data.displayPrice);
});
});
});
function qtyChanged(){
var inputqty = $('#inputqty').val();
var sku = $('#selSKU').val();
$.getJSON('pricecheck.cfc?method=getPrice&returntype=JSON&sku='+sku+'&qty='+inputqty, function(data) {
$("#divPrice").html(data.displayPrice);
});
};
</script>
最佳答案
看起来像 http://www.xxxxxxxx.co.uk/pricecheck.cfc?method=getPrice&returntype=JSON&sku=2947&qty=7
的结果包含错误。
//{"displayPrice":"£2.87 excl. VAT<\/strong>
(£3.44 incl VAT)<\/span>"}
注意 JSON 前缀的注释(双斜杠)。
如果 JSON 包含语法错误,$.getJSON 看起来也会无提示地失败:Why does $.getJSON silently fail?
关于Javascript JSON 函数不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15635818/