Refresh a div in Django using JQuery and AJAX

后端 未结 3 705
隐瞒了意图╮
隐瞒了意图╮ 2020-12-09 07:24

I am trying to refresh a certain part of my page with AJAX and JQuery (in Django). How can I get it to redisplay only the div, rather than the whole page.

           


        
3条回答
  •  粉色の甜心
    2020-12-09 08:03

    Use load:

    $('#tag_cloud').load(' #tag_cloud')
    

    (Note the leading space in the load parameter; this specifies an empty string [which evaluates to the current page] as the source, and "#tag_cloud" as the fragment to load)

    This will actually load #tag_cloud (including its outer html) into #tag_cloud, so you'll essentially get the following structure in your DOM:

    tag ...

    To fix this, just unwrap the children:

    $('#tag_cloud').load(' #tag_cloud', function(){$(this).children().unwrap()})
    

    Oh, by the way... you can try this here on SO! Just paste the following into your Firebug console, and watch the sidebar auto-reload. You'll notice some scripting code poking through; that's jQ's HTML-safety filters disabling the

提交回复
热议问题