开发者

html body tag limitations in chrome and 'I.E'

to boost up the performance of the web site i put all the contents from the db ( not very big ) to body data tag. i.e.

<body data-blog="<?php echo htmlspecialchars( json_encode($blog) ); ?>">

The site worked ok on localhost and i updated it to the live server.

When i access the data from this site it is working fine no problem here. The problem comes when some one else accesses the site. I tested it using firefox 4. on my computer it works but it does not work on any other computer. It does show the 开发者_高级运维data in the body tag but the simple javascript fails to display content without giving any error.

I do not know how can i debug this and what could be the potential problem with it. below is the code i am using to display the data out of the body tag.

<body data-blog="<?php echo htmlspecialchars( json_encode($blog) ); ?>">
        <script>
$(document).ready(function()
{
    $("#h_menu li").click(function(e)
    {

         var cid = $(this).attr('id');
         $("#contents").empty();
          var blog = $(document.body).data('blog');
            var tags = $.parseJSON(blog);


            $("#tmenu").empty();


                for(var n in tags)
                {
                    if( tags[n].cat_id == cid )
                        $('#tmenu').append("<li id='"+tags[n].id+"'>"+ tags[n].tag_name +"</li>");
                }
    });
    $("#tmenu li").live("click",function()
    {
        var id =  $(this).attr('id')  ;
        var blog = $(document.body).data('blog');
        var tags = $.parseJSON(blog);
        $('#contents').empty().hide();
        $('#contents').html(tags[id-1].tag_content).fadeIn(600);
    });
});
</script>

I forgot to mention it only works in FF4, chrome and I.E doesn't show data even on my computer from localhost so i am sure i must be doing some thing WRONG. but which thing i dont know and why is it working even from live site in my firefox ?


I think it would be better to stick that data in an hidden element somewhere instead of using the data. Also data is meant to be written and read using jQuery, I don't know if writing directly data-blog in the html will do the same without issues.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜