gpt4 book ai didi

javascript - 使用 jQuery AJAX 调用方法

转载 作者:行者123 更新时间:2023-12-02 20:43:34 24 4
gpt4 key购买 nike

我有这段代码来尝试从 codeigniter 中的 Controller 调用方法,

$("#Blog").click(function () {
var url = $(this).attr("href");
$.ajax ({
url: "index.php/home/category",
type: "POST",
success : function (html) {
$("#right-content").append(html);
}
});
});

ajax 似乎没有被解雇,是不是我遗漏了什么,#Blog 代表我的导航菜单中链接的 ID,所发生的只是链接正常工作。

请有人帮忙:-(

最佳答案

您需要防止发生正常的链接行为。

$("#Blog").click(function (e) {
var url = $(this).attr("href");

// Block the normal click action
e.preventDefault();

// Create post
$.post (
"index.php/home/category", // <- request URI
{url: url}, // <- any data goes here
function (html) { // <- callback
$("#right-content").append(html);
}
});
});

此外,您可能想查看 $.post 的文档.

关于javascript - 使用 jQuery AJAX 调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1866226/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com