我无法从 ajax 调用中输出 json

I can't output json from ajax call

我正在使用 Joomla 开发价格计算器,我创建了一个插件用于我的 ajax 功能。

貌似还可以,但是获取到数据后,无法输出

这是我的 jquery 代码,来自 ajax 请求:

jQuery(document).ready(function(){
    jQuery("#postcode-search").keyup(function(){
        jQuery('#priceList ul').html('');
        jQuery('#priceList').hide();
        jQuery.ajax({
        type: "POST",
        url: "index.php?option=com_ajax&plugin=PriceCalculator&format=json",
        dataType: "json", 
        data:'keyword='+jQuery(this).val(),
        beforeSend: function(){
            jQuery("#search-box").css("background","#FFF url(LoaderIcon.gif) no-repeat 165px");
        },
        success: function(data){
console.log(data);

            jQuery("#suggesstion-box").show();
            jQuery("#suggesstion-box").html(data.Postcode);
            jQuery("#search-box").css("background","#FFF");

        }
        });
    });
});

我通过控制台日志得到这个数组:

"[{"id":"1110","Postcode":"W11 1AA","Heathrow":"43","Luton":"58","Stansted":"58","Gatwick":"53","pcat":"W11"},{"id":"1111","Postcode":"W11 1AB","Heathrow":"43","Luton":"58","Stansted":"58","Gatwick":"53","pcat":"W11"},{"id":"1112","Postcode":"W11 1AD","Heathrow":"43","Luton":"58","Stansted":"58","Gatwick":"53","pcat":"W11"},{"id":"1113","Postcode":"W11 1AE","Heathrow":"43","Luton":"58","Stansted":"58","Gatwick":"53","pcat":"W11"},{"id":"1114","Postcode":"W11 1AF","Heathrow":"43","Luton":"58","Stansted":"58","Gatwick":"53","pcat":"W11"}]"

enter image description here

请问我做错了什么?

验证您的 api returns 有效 json,并确保 'Content-Type: application/json' 在响应 header 中设置。

https://www.getpostman.com/ 是一个很有价值的开发工具 RestAPI:s 它可能会帮助您调试问题。