How to reload a div without reloading the whole page?

I believe that what I ask is very simple for most of you. I want to reload the div without reloading the whole page. What is the best way to do this?

<div class="black_text" id="cp_in_content_div"> <?php $id = $_GET["id"]; $result = mysql_query("SELECT * FROM Setting WHERE ID = $id"); $row = mysql_fetch_array($result); switch ($_GET["action"]) { case "delete": if (!unlink("$_SERVER[DOCUMENT_ROOT]setting/$row[Filename]")) { echo "Error."; header("Refresh: 2.5; URL=delete_setting.php?id=$id"); exit(); } if (!mysql_query("DELETE FROM Setting WHERE ID = $id")) { echo "Error."; header("Refresh: 2.5; URL=delete_setting.php?id=$id"); exit(); } else { echo "Ok!"; header("Refresh: 1.25; URL=index.php"); } break; default: echo "form"; } ?> </div> 

I need this title ("Refresh: ...") to reload the div instead of the page.

+6
source share
4 answers

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

Note that loading allows you to use a selector to indicate which part of the loaded script you want to load, as in

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

Note that this technically loads the entire page, and jquery removes everything except what you selected, but it's all done internally.

+12
source
 $("#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> 
+7
source

write button tag and click button

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

write it all onclick function

+1
source

Use this.

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

Note, include a space before the hastag.

+1
source

Source: https://habr.com/ru/post/895739/


All Articles