How can I load an external page into a div using jquery?

I have a menu with 3 links when the user clicks on the menu link. I want the page to load on a div on the same page using jquery, im using php and mysql!

Thank you!

+3
source share
6 answers

Deployed from @jAndy example:

Markup:

<a href="/foo/bar.html" id="baz">Load external html</a>
<div id="result"></div>

Javascript

$('#baz').click(function () { $('#result').load(this.href); });
0
source

http://api.jquery.com/load/

$('#result').load('ajax/test.html');
+3
source
$('#local_container').load('external/file.php #external_container');

http://api.jquery.com/load/

+1
0

@jQuery.

, :

$.ajax({
  url: 'ajax/test.html',
  success: function(data) {
    $('.result').html(data);
    alert('Load was performed.');
  }
});
0

ajax mysql.

$.ajax({
  type: 'post',
  url: 'getnames.php',
  datatype: "json",
  success: function(data) {
    $('#id_of_the_div').text("");
    $('#id_of_the_div').append(data.returned);
  }
});

php:

//..
// commands that run mysql queries and gather information from database
//..
//..
//..
// you store what you've got from the database in a $ret variable and then:
// $ret can be for example:
// $ret = "<table><tr><td>Peter</td><td>40</td></tr></table>";

$arr = Array("returned"=>$ret);
echo json_encode($arr);

, , . ajax json...

0

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


All Articles