我知道还有其他这样的帖子,但经过它们之后,我仍然无法弄清楚如何使用ajax在我的页面上重新加载div而不刷新整个页面。
答案 0 :(得分:1)
为了完成这项工作,您必须包含将提供您尝试加载到div中的响应的URL。
$( "#cart" ).click(function() {
$( "#drawer-indiv-product" ).load( "some-url.html #drawer-indiv-product");
});
这来自load()文档:http://api.jquery.com/load/,URL参数是必需的。
编辑: 您可以使用类似的内容来了解有关您收到的数据的更多信息:
$( "#cart" ).click(function() {
$( "#drawer-indiv-product" ).load( "some-url.html #drawer-indiv-product", function(response, status, xhr) {
if (status == "error") {
console.log(xhr.status + " " + xhr.statusText);
}
else {
console.log(response);
}
}
});
答案 1 :(得分:1)
您错误地使用了load
方法。根据{{3}},您可以从远程文档加载片段,但为了做到这一点,您需要使用正确的语法。例如:
$( "#drawer-indiv-product" ).load("/resource/load.html #drawer-indiv-product");
答案 2 :(得分:0)
正确使用负载。另外,在onclick结尾处添加return false
。它将阻止常见的链接行为 - 重新加载页面。