开发者

Javascript json

does anyone know what this is not working? i have been trying for days now.

function loadContent(obj, getcmt)
{
var params = $(obj).attr('href').split('?');

$.get(BASE_DIR+'co开发者_如何学运维ntent/load.php?'+params[1],
     function(json) {
       var result = eval('('+json+')');
       if (result.returnval == 1) {
         $('#content').fadeOut('fast', function() { $(this).html(result.content).fadeIn('slow'); });

       }
    });
return false;
}

Firebug just give an error "missing } after property list" and link to jquery. and another debugger show json as the reason why.

any help is greatly appreciated!

EDIT:

The top work fine but the following dont work:

<div id="content">
    <a href="{$content.item_url}" onclick="return loadContent2(this, 'page', '2')">
</a>
</div>

how ever if the single quote in onClick is not there, it work. like so:

<div id="content">
    <a href="{$content.item_url}" onclick="return loadContent2(this, "page", "2")">
</a>
</div>

However the function in question loadContent2 does not work.


Try it using jQuery's built-in tools:

function loadContent(obj, getcmt) {
    var params = $(obj).attr('href').split('?');
    $.getJSON(BASE_DIR+'content/load.php?'+params[1], function(json) {
        if (json.returnval == 1) {
            $('#content').fadeOut('fast', function() { 
                $(this).html(json.content).fadeIn('slow');
            });
        }
    });
    return false;
}

This uses $.getJSON() which is awesome.

if that has problems, check your response:

$.getJSON(BASE_DIR+'content/load.php?'+params[1], function(json) {
    console.debug(json);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜