嗨,我是一名新程序员 我想使用 ajax 从 另一个 php 页面 替换当前 php 页面 的内容而不刷新页面。
要替换的内容在div的中。
两个页面(当前页面和另一个页面)都有相同的 div
HTML Div 是:
<div class="category-container">
<div class="category-image"></div>
<div class="category-desc"><a href="#">#</a><p>text</p></div>
<div class="rating5" >Editors' rating: </div>
<div class="category-download-btn"><a href="#">Download</a></div>
<div class="category-buy-btn"><a href="#">Buy</a></div>
</div>
谁能告诉我怎么做。这将是一个很大的帮助。 你也可以提供给我 ajax 代码而不是 jquery。
谢谢。
最佳答案
看看 jQuery 的 load
,关于加载页面片段的部分:
The .load() method, unlike $.get(), allows us to specify a portion of the remote document to be inserted.
要将另一个页面上的 div 内容放到当前页面上的类似 div 中,请使用如下内容:
$('#content').load('other-page.php #content');
// ^ target div ^ same div on the other page
关于php - 如何使用ajax从另一个页面加载内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10655891/