How to reload a div without reloading the entire page?

前端 未结 4 488
Happy的楠姐
Happy的楠姐 2020-12-08 18:02

I suppose what I am asking is really easy for most of you. I want to reload a div without reloading the entire page. What\'s the best way to do it?

相关标签:
4条回答
  • 2020-12-08 18:14

    jQuery.load() is probably the easiest way to load data asynchronously using a selector, but you can also use any of the jquery ajax methods (get, post, getJSON, ajax, etc.)

    Note that load allows you to use a selector to specify what piece of the loaded script you want to load, as in

    $("#mydiv").load(location.href + " #mydiv");
    

    Note that this technically does load the whole page and jquery removes everything but what you have selected, but that's all done internally.

    0 讨论(0)
  • 2020-12-08 18:26

    Use this.

    $('#mydiv').load(document.URL +  ' #mydiv');
    

    Note, include a space before the hastag.

    0 讨论(0)
  • $("#div_element").load('script.php');
    

    demo: http://sandbox.phpcode.eu/g/2ecbe/3

    whole code:

    <div id="submit">ajax</div> 
    <div id="div_element"></div> 
    <script> 
    $('#submit').click(function(event){ 
       $("#div_element").load('script.php?html=some_arguments');  
    
    }); 
    </script> 
    
    0 讨论(0)
  • 2020-12-08 18:27

    write a button tag and on click function

    var x = document.getElementById('codeRefer').innerHTML;
      document.getElementById('codeRefer').innerHTML = x;
    

    write this all in onclick function

    0 讨论(0)
提交回复
热议问题