为什么数据不会返回到getJSON成功处理程序?

时间:2012-04-25 23:38:12

标签: jquery json codeigniter

我正在调用getJSON并像这样循环结果,一切都运行良好:

$.getJSON( base_url + 'search/drill_down',{
        nextSelectName: nextSelectName,
        thisSelectName: thisSelectName,
        itemId: itemId
    }, function( r ) {
        $.each( r.items, function( k, v ) {
            //do stuff
        });
});

现在在某种情况下我需要返回一些HTML数据,但我仍然需要JSON用于原始状态,所以我想我只是将我的HTML编码为JSON,但数据永远不会返回!原始代码仍然可以正常工作,只有当我尝试返回编码为JSON的HTML时才会发生爆炸。

$.getJSON( base_url + 'search/drill_down',{
        nextSelectName: nextSelectName,
        thisSelectName: thisSelectName,
        itemId: itemId
    }, function( r ) {

        alert('working!'); // Not hitting this!

        if(r.tabs){
            $.each( r.tabs, function( k, v ) {
            var html = v[ 'html' ];
                return $('#content').html(html); // No need to continue, there is only one HTML string and no items.
            });
        }

        $.each( r.items, function( k, v ) { 
            //do stuff
        });
});

我在服务器上有一个断点(使用CodeIgniter),一切看起来都不错。我检查了我编码为JSON的HTML,它是有效的JSON。为什么我的服务器生成的JSON没有回到getJSON成功处理程序?

1 个答案:

答案 0 :(得分:1)

唯一的解释是请求是无用的,理由可能很多。有人可能会在错误的地方提出要求。使用

检查
console.log(base_url + 'search/drill_down');