Чтобы упростить этот процесс, добавьте на свою страницу библиотеку jQuery .
Ниже приведен пример использования jQuery для загрузки данных с другой страницы на текущую страницу:
inject_to = $("div#id"); // the div to load the html into
load_from = "/some/other/page"; // the url to the page to load html from
data = ""; // optional data to send to the other page when loading it
// do an asynchronous GET request
$.get(load_from, data, function(data)
{
// put the received html into the div
inject_to.html(data);
}
Обратите внимание, что это открывается для проблем безопасности / xss, и я бы рекомендовал использовать .text вместо .html и загружать только внешний текст с внешней страницы.Дополнительная информация о jQuery ajax: http://api.jquery.com/category/ajax/
Чтобы сделать это при нажатии кнопки, поместите приведенный выше код в функцию, например:
function buttonClicked()
{
inject_to = $("div#id"); // the div to load the html into
load_from = "/some/other/page"; // the url to the page to load html from
data = ""; // optional data to send to the other page when loading it
// do an asynchronous GET request
$.get(load_from, data, function(data)
{
// put the received html into the div
inject_to.html(data);
}
}
Затем добавьте обработчик события длясобытие click для кнопки, например:
$("button#id").click(buttonClicked);
Дополнительная информация о событиях jQuery: http://api.jquery.com/category/events/